I have a small package for creating dlls for use in mIRC - mdlldk. Faced with this situation, some questions arose about Nim and dlls, especially with regard to memory management.
I'll explain first how the mIRC dlls work (or I believe they work with the little documentation). There are 3 types of procedures called by mIRC. Two have pre-established names: LoadDll and UnloadDll; are called automatically by mIRC when loading or unloading the dll, as can be understood from the names. The third type of procedure are the ones you access directly from mIRC through the /dll, $dll or $dllcall calls, to extend the language.
The definitions in C are below:
typedef struct {
DWORD mVersion;
HWND mHwnd;
BOOL mKeep;
BOOL mUnicode;
DWORD mBeta;
DWORD mBytes;
} LOADINFO;
void __stdcall LoadDll(LOADINFO*);
int __stdcall UnloadDll(int mTimeout);
int __stdcall procname(HWND mWnd, HWND aWnd, TCHAR *data, TCHAR *parms, BOOL show, BOOL nopause)
Well, mIRC provides a pre-allocated memory pointer that you use to get information (parameter data) from mIRC and return it (parameter data and parms). There is also the LOADINFO object pointer that you can modify some BOOL types. So, in theory, there is no shared memory between the dll and mIRC (but mIRC shares it with the dll), because you copy into data and parms what you want to return to mIRC to analyze.
The mIRC dll documentation is here, in case my speech wasn't enough.
Now the questions that came to me are the following:
All of your questions can be effectively answered with a simple "yes". You understand the situation quite well.
My advice is to compile with --gc:orc -d:useMalloc, you don't need to worry about cycles and you don't need nimrtl.dll. Watch out though, it's often not clear which libc on Windows is used and some "mallocs" don't support DLLs well. Or to put it differently, it's best to ensure either of:
How cycles are formed and how to avoid them should be its own reply.
A long time ago I created a mIRC dll with C and I forgot to free a memory allocated with malloc and there was a leak. So, I believe that mIRC only controls the memory it allocates and the dll should be responsible for the memory it allocates itself.
Thanks for the reply and advice.
I would love some foundational article about Nim for standalone DLLs / .so, ideally without having to call NimMain so that for library consumers they work like C libraries.
This would be especially valuable for applications with a plugin system as well.
Truth. I started accessing IRC in 1999 with mIRC. And thanks to mIRC, around 2003/2004 I started programming, first in mIRC Scripting and then in Perl, PHP... Today I'm here with Nim.
Good times.