Hi all,

LoadLibrary automatically increment a reference count.

My question is: is there a way to know, given the HMODULE of a DLL, the current reference count for the own process?

Thanks.
Posted on 2002-07-05 09:19:12 by Maverick
Not with any API I am aware of... Perhaps a little reversing and debugging might help. :)
Posted on 2002-07-05 12:32:17 by comrade
Thank you comrade.
Thinking better about it, the reference count is probably global (i.e. not per process). It's my belief that Windows maps anyway a lot of DLL's that you never loaded (i.e. all the shared ones).
Can anybody confirm?
Posted on 2002-07-05 13:00:45 by Maverick

Module handles are not global or inheritable. A call to LoadLibrary by one process does not produce a handle that another process can use -- for example, in calling GetProcAddress. The other process must make its own call to LoadLibrary for the module before calling GetProcAddress.

If the module is a DLL not already mapped for the calling process, the system calls the DLL's DllEntryPoint function with the DLL_PROCESS_ATTACH value. If the DLL's entry-point function does not return TRUE, LoadLibrary fails and returns NULL.


Heyas Maverick,

The way the second paragraph reads to me is that Windows keeps count of DLLs for each process.
Posted on 2002-07-05 14:17:16 by Graebel
True that windows keeps a reference count for each process.
But it also maintains a global count in order to save memory (the way DLLs save memory).

Matt Piertrek's book 'win95 system programming secrets' has a thorough explanation of how to retrieve this global count under win95. For NT, I don't know.
Posted on 2002-07-06 02:58:01 by C.Z.