Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check dll's reference count? How to know where the dll was loaded?

Tags:

c++

windows

As you know, if the call to LoadLibrary specifies a DLL module already mapped into the address space of the calling process, the function simply returns a handle of the DLL and increments the module's reference count.

Somewhere, I need to get the reference count of a dll. How to get the dll's reference count? How to know where the dll was loaded? Thanks.

like image 491
ldlchina Avatar asked Aug 24 '10 02:08

ldlchina


2 Answers

I googled it, and found this article which claims to provide the answer. Sorry I couldn't be more helpful:

like image 75
C Johnson Avatar answered Sep 25 '22 22:09

C Johnson


If it is a non programmatic way (thanks to C.Johnson for giving that perspective), WinDBG could be helpful

http://windbg.info/doc/1-common-cmds.html#10_modules

Look at !dlls and it's variants.

!dll - all loaded modules with load count

EDIT 2:

If you want to know from where all the DLL is being loaded from the process, there are two ways:

a. Look at the command

"bu kernel32!LoadLibraryExW ";as /mu ${/v:MyAlias} poi(@esp+4); .if ( $spat( \"${MyAlias}\", \"MYDLL\" ) != 0 ) { kn; } .else { g }" "

in the above URL

b. Run the process under WinDBG. Debug->Even Filter and select "Load Module" and set it to "Enabled" under "Execution". Under "Continue" set it to "Not Handled".

One of these should help you definitely.

like image 33
Chubsdad Avatar answered Sep 23 '22 22:09

Chubsdad