The LoadLibraryA method returns error code 1114 (ERROR_DLL_INIT_FAILED) after more than 1000 cycles

Posted by Javier on Stack Overflow See other posts from Stack Overflow or by Javier
Published on 2010-06-10T20:43:27Z Indexed on 2010/06/10 21:22 UTC
Read the original article Hit count: 675

Filed under:
|
|

Hi,

I'm programing on C++, I'm using Visual Studio 2008, Windows XP, and I have the following problem: My application, that is a DLL that can be used from Python, loads an external dll, uses the required methods, and then unloads this external Dll. It's working properly, but after more than 1000 cycles the method "LoadLibraryA" returns a NULL reference.

The main steps are:

HINSTANCE h = NULL; h = LoadLibraryA(dllfile.c_str()); DWORD dw = GetLastError();

The error got is: ERROR_DLL_INIT_FAILED 1114 (0x45A) A dynamic link library (DLL) initialization routine failed.

The Dll is unloaded by using the following: FreeLibrary(mDLL); mDLL = NULL; Where mDLL is defined like this: HINSTANCE mDLL;

First alternative tried: Just load the Dll only once, and unloaded it when the application ends. This fix the problem but introduces a new one.

When the application ends, instead of first executing the DllMain method of my applicaion, wich unloads the external DLL, is executing first the DllMain method of the other Dll. This cause the following error because my application is trying to unload a Dll that was unload by itself previously.

"Unhandled exception at 0x04a00d07 (DllName.DLL) in Python.exe: 0xC0000005: Access violation reading location 0x0000006b".

Any suggestion will be welcomed. Thanks in advance. Regards.

© Stack Overflow or respective owner

Related posts about c++

Related posts about python