Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loaded Libraries

Status
Not open for further replies.

sweep123

Technical User
May 1, 2003
185
GB
If you load a library dynamically via the LoadLibrary("MyLib.DLL"); are they any facilities to see what the library is doing; i.e. number of thread running in it, stuck in a loop etc.
 
The dll will be part of you host process ie the dll doesnt run anything by itself. loops, threads etc is something that takes place in your application.

You can use the Process Viewer (VC++ 6.0 Tools) see threads.

Stuck in a loop? Check whether its eating lots of CPU without actually doing anything...

/Per

"It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure."
 
Actually, PerFnurt, the library could create additional threads which are internally controlled (by methods which are not exported and thus not accessible within your software).
One simple example is a multimedia timer (see timeSetEvent and related in MSDN).

A simple method to find the number of threads loaded by a library would be:

1) Create a snapshot using the CreateToolhelp32Snapshot API (from PS API - Tool Help Library). You would set the first parameter to TH32CS_SNAPTHREAD to create a snapshot of the existing threads, and the second parameter to 0 (zero) - ("This parameter can be zero to indicate the current process" according to MSDN).

2) After step 1) you parse the threads of the current process using Thread32First and Thread32Next which have a LPTHREADENTRY32 parameter (a structure).

3) For each thread in your process you compare its ID with the one found in the th32ThreadID member of the structure LPTHREADENTRY32 (remember, this structure is passed as parameter to Thread32First and subsequent Thread32Next calls, and it is filled by these 2 APIs).

4) If a thread ID of your process (all threads created by you, you will have to store all their IDs!!) does NOT match a th32ThreadID of the structure above, this means that the thread was created by the .DLL object (by exclusion [wink] [thumbsup] ).

Hope it was clear and helpful enough.

P.S.1: For more information, look for the above APIs and structures in MSDN.
 
>the library could create additional threads which are internally controlled

Sure, but you can still observe them with a tool such as Process Viewer, right?

/Per

"It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top