mIRC Home    About    Download    Register    News    Help

Print Thread
DLLs #2112 17/12/02 12:27 AM
Joined: Dec 2002
Posts: 1
S
souleh Offline OP
Mostly harmless
OP Offline
Mostly harmless
S
Joined: Dec 2002
Posts: 1
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.

Re: DLLs #2113 17/12/02 08:15 AM
Joined: Dec 2002
Posts: 9
C
Campino Offline
Nutrimatic drinks dispenser
Offline
Nutrimatic drinks dispenser
C
Joined: Dec 2002
Posts: 9
Why don't you write an application instead of a DLL?


-------
If you find any spelling mistakes, you can keep them for yourself
Re: DLLs #2114 17/12/02 09:51 AM
Joined: Dec 2002
Posts: 89
N
Necroman Offline
Babel fish
Offline
Babel fish
N
Joined: Dec 2002
Posts: 89
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.


Sincerely,
Necroman, #mIRC @ Undernet
Re: DLLs #2115 17/12/02 08:01 PM
Joined: Dec 2002
Posts: 2,809
C
codemastr Offline
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
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...

Re: DLLs #2116 18/12/02 09:26 AM
Joined: Dec 2002
Posts: 89
N
Necroman Offline
Babel fish
Offline
Babel fish
N
Joined: Dec 2002
Posts: 89


Sincerely,
Necroman, #mIRC @ Undernet