多一个按钮操作,LoadLibrary 就失败了。该如何处理

多一个按钮操作,LoadLibrary 就失败了。。。
初学,请教个问题。。,

我用VC 2008做个小工具,界面上弄了两个按钮A和B,
点击 A 调用自己单独编译的一个动态库,
点击B 弹出个文件选择对话框,选则某个文件,然后记下这个文件的全路径。

现在遇到一个问题:
如果不执行B,上来就点 A,那么 LoadLibrary 加载动态库返回的句柄正常,
如果先执行了 B,再点击 A,LoadLibrary 就会失败,句柄为空,错误126。

不理解这是什么情况,还请大家指点一二,谢谢啦。

------解决方案--------------------
这样说没人知道为什么,你单步跟进一下,或者把代码贴上来。
另外变量特别是字符串每次使用要初始化的
------解决方案--------------------
首先查一下126错误码是什么,然后再检查自己的代码是不是有问题,126错误:“ERROR_MOD_NOT_FOUND”。多半路径不对呗
------解决方案--------------------
ERROR_MOD_NOT_FOUND
126


应该是你弹出对话框后的当前目录被修改了。
你LoadLibrary 的时候用绝对路径试试。
------解决方案--------------------
如3楼所说,目测是你选择文件后改变了系统的当前目录,而你加载的动态库路径用的相对路径,所以...,改为绝对路径
------解决方案--------------------
估计是由于,楼主弹出CFileFind 的时候,将路径修改,然后,加载库失败 。
------解决方案--------------------
试试:
HINSTANCE hInst = LoadLibrary(_T("H:\\00.Buf\\01.Doc\\Visual Studio 2008\\Projects\\CAP\\CAP\\capture_dll_generate.dll"));

LoadLibrary
The LoadLibrary function maps the specified executable module into the address space of the calling process. 

HINSTANCE LoadLibrary(
  LPCTSTR lpLibFileName   // address of filename of executable module
);
 
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. 

Remarks
LoadLibrary can be used to map a DLL module and return a handle that can be used in GetProcAddress to get the address of a DLL function. LoadLibrary can also be used to map other executable modules. For example, the function can specify an .EXE file to get a handle that can be used inFindResource orLoadResource. Do not use LoadLibrary to "run" a .EXE file. 

If the module is a DLL not already mapped for the calling process, the system calls the DLL's DllMain function with the DLL_PROCESS_ATTACH value. If the DLL's entry-point function does not return TRUE, LoadLibrary fails and returns NULL. 

It is not safe to call LoadLibrary from DllMain. For more information, see the Remarks section in DllMain. 

Module handles are not global or inheritable. A call to LoadLibrary by one process does not produce a handle that another process can use — for example, in calling GetProcAddress. The other process must make its own call to LoadLibrary for the module before calling GetProcAddress. 

If no filename extension is specified in the lpLibFileName parameter, the default library extension .DLL is appended. However, the filename string can include a trailing point character (.) to indicate that the module name has no extension. When no path is specified, the function searches for loaded modules whose base name matches the base name of the module to be loaded. If the name matches, the load succeeds. Otherwise, the function searches for the file in the following sequence: