views:

34

answers:

2

Hello gurus,

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!

+1  A: 

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 contain 32 bit files - it contains files matching the bit size of the operating system, so on 32 bit Windows sytem32 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).

Joe Gauterin
The error message is actually a confirmation that the compiled DLL is indeed 64-bit, as it can't find all the necessary imports in a 32-bit DLL, which is quite logical, because a 32-bit DLL has no x64 contents.
rubenvb
A: 

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.

Kirill V. Lyadvinsky