views:

434

answers:

3

Exact Duplicate

Initialize Critical Section only once for a process

I have a dll that creates a global critical section, initializes and use it.

Now a third party application is using / loading the dll more than once which leads to a heap corruption.

The appverifier warns me with a

--> VERIFIER STOP 00000211: pid 0x1470: Critical section is already initialized. <--

Using a global flag to check if the critical section object is already initialized doesn't help, any ideas on accomplishing the same ?

Thanks

+1  A: 

Have you looked at this question for a possible answer?

http://stackoverflow.com/questions/724560/initialize-critical-section-only-once-for-a-process

James Black
A: 

Now a third party application is using / loading the dll more than once

Windows does not reload the same DLL multiple times. Where same means same path. If the 3rd party app is loading from different locations, that is the problem.

Richard
Windows can relaod the same DLL multiple times. DLLs are reference counted. You also have calls for process and thread start stop. If the loading app frees the library and loads it again this is entirely possible. It indicates no cleanup code on the critical section when the dll is freed.
Greg Domjan
The DLL will not be reloaded with another LoadLibrary call, the reference will be incremented, but DllMain will *not* be called.
Richard
A: 

May be using the "setAtom" and "getAtom" APIs help? I know they are a bit "old-school" but you can never know.

BYK