Use loadlibrary to display and load dynamic libraries:
Hinstance hdll; // DLL handle
Hdll = loadlibrary ("user32.dll ");
If (hdll! = NULL)
{
}
The result always jumps out of if directly, and DLL loading fails.
After other problems are ruled out, the following statement is successfully called:
Hdll = loadlibrary (text ("user32.dll "));
Baidu and Google discovered that it was originally caused by character formats.
Loadlibrary actually uses loadlibraryw instead of loadlibrarya. Therefore, a unicode string (wide string) instead of a narrow string is required, as shown below:
# Ifdef Unicode
# Define loadlibrary loadlibraryw
# Else
# Define loadlibrary loadlibrarya
# Endif //! Unicode
In C/C ++ code, the string defined by "" is a narrow byte string, while the text macro provided in the Windows header file can be defined based on whetherUnicodeMacro to automatically select the string type.
Therefore, the text macro is used to automatically select the correct character set. The DLL is successfully called.
PS: The loadlibrary function and LoadLibraryEx function have different mechanisms for loading the DLL. The former will automatically load the DLL when loading other DLL dependent on the DLL, while the latter will not, there are examples on the Internet that failed to load their own DLL. If you want to solve the Path Problem (it is best to use the full path), you should consider whether the DLL depends on other DLL.