Suppose i have program a.exe which loads b.dll which spawns c.thread:

a.exe -> b.dll -> c.thread

Then i launch a second copy of a.exe which loads b.dll and tries to spawn c.thread but can't because i have protected it with a mutex. Now if i close the first copy of a.exe will c.thread still run?

What i want to do is have my dll spawn a thread that is to remain running until the last program that is using the dll closes; regardless of which instance of a.exe it was who spawned the thread...

Is this possible?
Posted on 2001-12-07 09:10:40 by Zynaps
As I understand it, when the final app that uses a DLL is unloaded,
the DLL reference count goes to 0, and the DLL will be unloaded
(active threads or not).

I'm not sure if there's a way you can get the reference count, but
otherwise you might want to put your own reference count variable
in a global/shared memory area, and do handling in DLL_PROCESS_ATTACH
and DLL_PROCESS_DETACH.
Posted on 2001-12-07 10:37:57 by f0dder
If you created a shared segemnt inside the Dll, by using link.exe with the option /SECTION:'SectionName',SRW then you could easily store an instance count in the area, which would be shared and accessible by all processes using this Dll for read/write acess.

When the instance count get down to 1 then this process would be the last one running.


Assmble:


Share32 SEGMENT PUBLIC FLAT USE32
uInst DWORD ?
Share32 ENDS


DllMain PROC .........
.IF fdwReason==DLL_PROCESS_ATTACH
inc uInst
.ELSEIF ............



link:


\masm32\bin\link.exe /SECTION:Share32,SRW ..............
Posted on 2001-12-08 20:14:16 by huh