mIRC Homepage
Posted By: souleh DLLs - 17/12/02 12:27 AM
How can I load a DLL from mIRC so that it stays in memory, but executes in a new thread, so as not to cause mIRC to freeze while the dll is executing? It runs in a long loop receiving debug messages from an application, which I want to relay to mIRC. I want to keep mIRC responsive - yet how do I keep mIRC up to date with the latest messages the DLL receives as they arrive? (Think an EnumWindows type situation, with the DLL acting as Windows).

Thanks for your help.
Posted By: Campino Re: DLLs - 17/12/02 08:15 AM
Why don't you write an application instead of a DLL?
Posted By: Necroman Re: DLLs - 17/12/02 09:51 AM
Create a new thread from your DLL, using _beginthread (or CreateThread, if you've excluded the C run-time library from your project), store it's handle somewhere and return.

You will possibly want to create some flag (a global variable, or Event) which would indicate that the "worker" thread should terminate. In your UnloadDll function, set the flag and wait for the worker thread to exit (using WaitForSingleObject).

Remember not to use the single-threaded version of the C run-time library.

Call the SendMessage function to notify mIRC of an incoming event. Since you create an additional thread that can conflict with other DLLs accessing the file mapping, use the "mIRC_SendMessage" mutex for synchronization.
Posted By: codemastr Re: DLLs - 17/12/02 08:01 PM
If you are going to use WaitForSingleObject then you can NOT use _beginthread. You need _beginthreadex. _beginthread auto calls _endthread and CloseHandle() when the thread terminates. WaitForSingleObject has undefined results if CloseHandle() is called on a handle while you are waiting on it...
Posted By: Necroman Re: DLLs - 18/12/02 09:26 AM
indeed
© mIRC Discussion Forums