msdn中的描述:
The LoadLibrary function maps the specified executable module into the address space of the calling process.
HINSTANCE LoadLibrary(LPCTSTR lpLibFileName);
Parameters
-
lpLibFileName
-
Pointer to a null-terminated string that names the executable module (either a .DLL or .EXE file). The name specified is the filename of the module and is not related to the name stored in the library module itself, as specified by the
LIBRARY keyword in the module-definition (.DEF) file.
If the string specifies a path but the file does not exist in the specified directory, the function fails. When specifying a path, be sure to use backslashes (/), not forward slashes (/).
If the string does not specify a path, the function uses a standard search strategy to find the file. See the Remarks for more information.
Return Values
If the function succeeds, the return value is a handle to the module.
If the function fails, the return value is NULL. To get extended error information, call GetLastError.
说明:如果函数调用成功则返回一个句柄(32位无符号整型),并且句柄值大于32;如果函数调用失败则返回NULL,这时可以调用GetLastError()函数来获得扩展的错误信息。注意,如果LoadLibrary函数调用返回NULL,即函数调用失败,而此时调用GetLastError()函数得到的扩展错误信息为0时,最可能的原因是你自己的程序逻辑上有问题。应该仔细检查代码的逻辑。最常的情况是其他使用了该DLL中函数的线程发生了异常,导致DLL被自动释放。即,DLL刚被加载成功,随即又被释放,并由应用程序自身的代码将该DLL的句柄设置为NULL。以前我自己做的一个多线程服务器加载DLL就出现过这种现象,后来发现是采样线程中的一个函数错误导致的。