1
votes

I am compiling some external C++ code into a dll using Visual Studio 2008. The code is wrapped in extern "C".

Since I am cross compiling, creating a 64 bit dll on my 32 bit machine; I am using x64 as "Active solution platform" in the "Configuration Manager".

My dll compiles and links successfully. However when I open it in Dependency Walker (depends.exe) I notice something strange: My dll is marked as 64 bit. My dll however depends on C:\windows\system32\ntdll.dll and C:\windows\system32\kernel32.dll which are 32 bit! As a result Dependency Walker gives me the following errors: "Error: At least one module has an unresolved import due to a missing export function in an implicitly dependent module. Error: Modules with different CPU types were found."

What is going wrong here?

Thanks in advance for any answers!

3
For backward compatibility on a 64 bit machine the files from system32 are actually the 64 bit ones. So on a 64 bit machine ntdll.dll and kernel32.dll would be actually 64 bit versions. The 32 versions are located in SysWow64.Adrian Fâciu

3 Answers

2
votes

Dependency walker gives you that error because the dll files in system32 on your 32 bit system are 32 bits. If you run it on a 64 bit version of Windows it will work fine.

Perhaps the misunderstanding comes from the name of system32? It doesn't necessarily contain 32 bit files - it contains files matching the bit size of the operating system, so on 32 bit Windows sytem32 contains 32 bit dlls, and on 64 bit Windows system32 contains 64 bit dlls.

It gets more complicated though - 64 bit Windows can run 32 bit processes, and if a 32 bit process accesses system32 on a 64 bit version of Windows, that access it gets redirected to the SysWOW64 (yes system32 contains 64 bit dlls and SysWOW64 contains 32 bit dlls).

1
votes

Your DLL depends on ntdll.dll and kernel32.dll. Dependency Walker tries to find them according to lookup rule of the LoadLibrary function. And it finds them in system32 directory, but on 32-bit system they are 32-bit.

0
votes

Use 64 bit version of Dependency Walker to open your 64 bit version of dll's. You will no longer see the error message, "Error: Modules with different CPU types were found", if your modules are properly compiled for x64.