首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

VS2010程序中Debug调用不到Debug的dll,但可以调用到release版的dll解决思路

2013-11-14 
VS2010程序中Debug调用不到Debug的dll,但可以调用到release版的dllVS2010程序Debug可以调用Debug的dll。但

VS2010程序中Debug调用不到Debug的dll,但可以调用到release版的dll


VS2010程序Debug可以调用Debug的dll。但后来程序Debug版调用不到Debug的dll,但可以调用到release版的dll。求指教。
因为这样就变得没法调试了。

VS2010
[解决办法]
用depends.exe查看exe依赖的dll
path环境变量中各目录的顺序影响查找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: 

The directory from which the application loaded. 
The current directory. 
Windows 95 and Windows 98: The Windows system directory. Use theGetSystemDirectory function to get the path of this directory.
Windows NT: The 32-bit Windows system directory. Use the GetSystemDirectory function to get the path of this directory. The name of this directory is SYSTEM32. 



Windows NT: The 16-bit Windows system directory. There is no function that obtains the path of this directory, but it is searched. The name of this directory is SYSTEM. 
The Windows directory. Use theGetWindowsDirectory function to get the path of this directory. 
The directories that are listed in the PATH environment variable. 
The first directory searched is the one directory containing the image file used to create the calling process (for more information, see the CreateProcess function). Doing this allows private dynamic-link library (DLL) files associated with a process to be found without adding the process's installed directory to the PATH environment variable. 

The Visual C++ compiler supports a syntax that enables you to declare thread-local variables: _declspec(thread). If you use this syntax in a DLL, you will not be able to load the DLL explicitly using LoadLibrary or LoadLibraryEx. If your DLL will be loaded explicitly, you must use the thread local storage functions instead of _declspec(thread). 

Windows 95: If you are using LoadLibrary to load a module that contains a resource whose numeric identifier is greater than 0x7FFF, LoadLibrary fails. 

Windows CE: Two different modules cannot have the same filename, given that the extensions are different. These effectively have the same "module" name. For example, if LoadLibrary is made on "Sample.cpl", the operating system will not load Sample.cpl, but instead will again load Sample.dll. A similar limitation exists for modules with the same name but residing in different directories. For example, if LoadLibrary is called on "\\Windows\Sample.dll", and then LoadLibrary is called on "\\MyDir\Sample.dll", "\\Windows\Sample.dll" will simply be reloaded.

A search path to the executable module cannot be specified. Unless the full path to the module is given, Windows CE will search the following path for the module: 

The root directory of the PC Card RAM expansion card, if one exists. 
The windows directory (\Windows). 
The root directory (\). 
QuickInfo
  Windows NT: Requires version 3.1 or later.
  Windows: Requires Windows 95 or later.
  Windows CE: Requires version 1.0 or later.
  Header: Declared in winbase.h.
  Import Library: Use kernel32.lib.
  Unicode: Implemented as Unicode and ANSI versions on Windows NT.

See Also
Dynamic-Link Libraries Overview, Dynamic-Link Library Functions, DllMain,FindResource, FreeLibrary, GetProcAddress,GetSystemDirectory,GetWindowsDirectory, LoadLibraryEx,LoadResource 

 


[解决办法]
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: 

The directory from which the application loaded. 
The current directory. 
Windows 95 and Windows 98: The Windows system directory. Use theGetSystemDirectory function to get the path of this directory.
Windows NT: The 32-bit Windows system directory. Use the GetSystemDirectory function to get the path of this directory. The name of this directory is SYSTEM32. 

Windows NT: The 16-bit Windows system directory. There is no function that obtains the path of this directory, but it is searched. The name of this directory is SYSTEM. 
The Windows directory. Use theGetWindowsDirectory function to get the path of this directory. 
The directories that are listed in the PATH environment variable. 
The first directory searched is the one directory containing the image file used to create the calling process (for more information, see the CreateProcess function). Doing this allows private dynamic-link library (DLL) files associated with a process to be found without adding the process's installed directory to the PATH environment variable. 

The Visual C++ compiler supports a syntax that enables you to declare thread-local variables: _declspec(thread). If you use this syntax in a DLL, you will not be able to load the DLL explicitly using LoadLibrary or LoadLibraryEx. If your DLL will be loaded explicitly, you must use the thread local storage functions instead of _declspec(thread). 

Windows 95: If you are using LoadLibrary to load a module that contains a resource whose numeric identifier is greater than 0x7FFF, LoadLibrary fails. 

Windows CE: Two different modules cannot have the same filename, given that the extensions are different. These effectively have the same "module" name. For example, if LoadLibrary is made on "Sample.cpl", the operating system will not load Sample.cpl, but instead will again load Sample.dll. A similar limitation exists for modules with the same name but residing in different directories. For example, if LoadLibrary is called on "\\Windows\Sample.dll", and then LoadLibrary is called on "\\MyDir\Sample.dll", "\\Windows\Sample.dll" will simply be reloaded.



A search path to the executable module cannot be specified. Unless the full path to the module is given, Windows CE will search the following path for the module: 

The root directory of the PC Card RAM expansion card, if one exists. 
The windows directory (\Windows). 
The root directory (\). 
QuickInfo
  Windows NT: Requires version 3.1 or later.
  Windows: Requires Windows 95 or later.
  Windows CE: Requires version 1.0 or later.
  Header: Declared in winbase.h.
  Import Library: Use kernel32.lib.
  Unicode: Implemented as Unicode and ANSI versions on Windows NT.

See Also
Dynamic-Link Libraries Overview, Dynamic-Link Library Functions, DllMain,FindResource, FreeLibrary, GetProcAddress,GetSystemDirectory,GetWindowsDirectory, LoadLibraryEx,LoadResource 

 

[解决办法]
87 参数不正确。
[解决办法]
ASSERT(0==_taccess(dllName,0));//断言文件dllName存在
HMODULE g_hDll = LoadLibrary( dllName ); //g_hDll值为空
int n = GetLastError(); //n = 87
[解决办法]
莫非你这个dll文件坏了?

重新生成或从http://www.dllzj.com下载一个再试试?

或者试试用PEBrowse Professinal软件打开这个dll。

或者使用前需要注册regsvr32 XXXX.dll ?

不是动态调用的话,没必要在代码中写LoadLibrary,只需要设置正确的:
项目、属性、链接器、常规、附加库目录:填写附加依赖库所在目录 分号间隔多项
项目、属性、链接器、输入、附加依赖项:填写附加依赖库的名字.lib 空格或分号间隔多项

[解决办法]
路径不对,版本不对,函数调用约定不对。。。。。
[解决办法]
用depends.exe查看exe依赖的dll

提醒:不要被文件名迷惑,注意观察文件的生成日期时间。
Debug版和Release版的dll最大的区别体现在以下几个方面:
◆内部带不带调试符号
◆堆栈检查是否开启
◆代码是否优化过
◆……

会用WinDbg调试对应汇编指令才是调试的根本。
对学习编程者的忠告:
眼过千遍不如手过一遍!
书看千行不如手敲一行!
手敲千行不如单步一行!
单步源代码千行不如单步对应汇编一行!

[解决办法]
很多人说C/C++没有源代码或调试符号就无法调试,那是因为他不会调试C/C++对应汇编指令。
[解决办法]

引用:
http://blog.csdn.net/huangxy10/article/details/7616633

个人意见:这样改完之后已经不是Release版了。

热点排行