LoadLibrary failed to load dynamic library

LoadLibrary to load dynamic library failed Possible Causes and Solutions:

(1) dll dynamic library files wrong path. This scene is subdivided into the following situations:

1.1 file path is indeed wrong . For example: the original is to be loaded dynamic library a.dll under the A folder, but after careful investigation and the reasons found a.dll dynamic library is now being copied to the B folder anymore.

If that encounter such a stupid mistake, I suggest you find no one in the corner with a squat little finger counterclockwise designated circle go. . .

1.2 argument passed by value error. For example: type argument LPCWTR, will often lead to argument because the string conversion backfire.

Online lessons learned instance. A programmer After some difficulty successfully invoked by the following statement

hDll = LoadLibrary(TEXT("user32.dll"));

After some google Baidu then discovered that the character format is to blame.

LoadLibrary here instead of LoadLibraryA LoadLibraryW practical use, it is necessary UNICODE string (string width), instead of a narrow string. as follows:

#ifdef UNICODE

#define LoadLibrary  LoadLibraryW

#else

#define LoadLibrary  LoadLibraryA

#endif //! UNICODE

In C / C ++ code, direct use of "" is defined as a string of narrow byte strings, windows and the TEXT macro file header may be provided depending on whether the macro is defined to automatically select the UNICODE string type.

Therefore, use the TEXT macro to automatically select the correct character set , dll call was successful.

(2) DLL initialization failure, there are global variables or dllmain function returns false . This situation requires the code according to their specific business analysis excluded and positioning.

(3) 64-bit process calls the 32-bit dynamic library dll problem.

Microsoft's official website for this issue is described as follows:

64-bit windows system, a process can not load a 64-bit 32-bit dll, the same way a 32-bit process can not load a 64-bit dll.

If you really do not have the source code, so be it "embarrassing" would like running, you can see information on "issues and thinking 32 dll solution / program 64 brings 64-bit process calls"

(4) other reasons

4.1 LoadLibrary function with LoadLibraryEx function is not the same dll loading mechanism will be automatically loaded when the former encounter other dependent dll and the dll loading dll, while the latter will not.

There are loads of online examples of their own dll not succeed, excluding path problems, then (the best full path), it is necessary to consider whether the dll to rely on other dll.

 

Original: https://www.cnblogs.com/Braveliu/p/9342633.html

 

Guess you like

Origin www.cnblogs.com/xiangtingshen/p/11371815.html