开发者

Why does MSVC 2010 32bit project link to 64bit kernel32.dll?

开发者 https://www.devze.com 2023-03-07 17:50 出处:网络
I have a Win32 (32bit) DLL project which builds and links without error. The DLL fails to load into a 32bit process. Using DependencyWalker, I see that the DLL is 32b开发者_JAVA技巧it but has been lin

I have a Win32 (32bit) DLL project which builds and links without error. The DLL fails to load into a 32bit process. Using DependencyWalker, I see that the DLL is 32b开发者_JAVA技巧it but has been linked with 64bit libraries for kernel32, msvcr100d, ws2_32 and msvcr100.

DependencyWalker also shows an error

Error: Modules with different CPU types were found.

I've puzzled over this problems for a couple of hours now, and just can't fathom it - has anyone else experienced this, and found a solution?


Short Answer: Use Dependency Walker for x86 for x86 stuff.

Long Answer: Initially I used Dependency Walker for x64 on the MS Windows 7 OS and ran into the hurdles you did. I then followed MerickOWA's advice about changing the search paths (thanks MerickOWA). Though I still had a handful of dependencies causing "Error: Modules with different CPU types were found".

Instead of figuring out how to configure Dependency Walker to search for the x86 DLLs in bizarre looking paths like "c:\windows\winsxs\amd64_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.7601.17514_none_2b24536c71ed437a\GDIPLUS.DLL" correctly, I used the Dependency Walker for x86. Worked like a charm for me!


Dependency Walker isn't using the same search path as the OS. It has its own search paths to try and find DLLs. You can view this by going to "Options -> Configure Module Search Order..."

Unfortunantly its search paths don't include "C:\Windows\SysWow64" (the location of the 32 bit version for Kernel32.dll)

This is why Dependency Walker incorrectly thinks your application is mixing x64 DLLs with your x86 application.

If you fix up the search order to include SysWow64 and remove all references to the System32 directory. This error should go away.

A better way to check which the output window of Visual Studio debugger or WinDbg when your application is run. It will list out the DLL's full path as they're loaded.


Check out the dependency website FAQ. http://www.dependencywalker.com/faq.html

Q.Will Dependency Walker work with 64-bit modules?

you need use the x86 version for the 32bit modules, x64 for the 64bit modules. It means you need have 2 copy in the 64bit OS and use them accordingly.

you can use the windows registry to create the context menu in order to save your trouble like this.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\dllfile\shell]

[HKEY_CLASSES_ROOT\dllfile\shell\View Dependencies]

[HKEY_CLASSES_ROOT\dllfile\shell\View Dependencies\command]
@="\\\\psf\\Public\\Library\\DEPE~K17\\depends.exe /dde"

[HKEY_CLASSES_ROOT\dllfile\shell\View Dependencies\ddeexec]
@="[open(\"%1\")]"

[HKEY_CLASSES_ROOT\dllfile\shell\View Dependencies(32bit)]

[HKEY_CLASSES_ROOT\dllfile\shell\View Dependencies(32bit)\command]
@="\\\\psf\\Public\\Library\\DEPE~K17\\x86\\depends.exe /dde"

[HKEY_CLASSES_ROOT\dllfile\shell\View Dependencies(32bit)\ddeexec]
@="[open(\"%1\")]"

[HKEY_CLASSES_ROOT\exefile\shell]

[HKEY_CLASSES_ROOT\exefile\shell\View Dependencies]

[HKEY_CLASSES_ROOT\exefile\shell\View Dependencies\command]
@="\\\\psf\\Public\\Library\\DEPE~K17\\depends.exe /dde"

[HKEY_CLASSES_ROOT\exefile\shell\View Dependencies\ddeexec]
@="[open(\"%1\")]"

[HKEY_CLASSES_ROOT\exefile\shell\View Dependencies(32bit)]

[HKEY_CLASSES_ROOT\exefile\shell\View Dependencies(32bit)\command]
@="\\\\psf\\Public\\Library\\DEPE~K17\\x86\\depends.exe /dde"

[HKEY_CLASSES_ROOT\exefile\shell\View Dependencies(32bit)\ddeexec]
@="[open(\"%1\")]"
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号