I’m not asking for the SO to tell me what the problem is, I’m just asking what sanity checks should I run in a case like this.
Using Visual Studio 2005, plain c++ project. Actual code is:
int Sum(int a, int b)
{
return a+b;
}
No pre-compiled headers. Exported with a DEF file:
LIBRARY testdll
EXPORTS
Sum
Compiled on a test machine (VS2005 again), the DLL works on other machines (64 bit and 32 bit tested, always compiled with a Win32 target platform). Compiled on my machine (64 bit, same project, same properties), the DLL works only on my machine, on others it starts the Just-In-Time Debugger (or crashes horribly if JIT isn’t installed):
Unhandled exception at 0x00000000 in Caller.exe: 0xC0000005: Access violation reading location 0x00000000.
At first I was calling it with j on my test machines, and that would fail too, giving me (with cder) a “file not found” error.
Other symptom: File size is different, my machine gives the DLL an extra 512 bytes.
My system configuration:
- Windows Vista – 64 bit
- VS2005 Version 8.050727.867 (vsvista.050727-8600)
- .NET Framework Version 2.0.50727 SP2
Tested environments:
- Windows XP – 32 bit (virtual machine)
- VS2005 Version 8.0.50727.42 (RTM.050727-4200)
-
.NET Framework Version 2.0.50727 SP2
-
Windows XP – 64 bit
- VS2005 Version 8.0.50727.42 (RTM.050727-4200)
- .NET Framework Version 2.0.50727 SP2
I suppose that “Win32 target platform” is wrong configured on your 64-bit machine. I recommend you to start “Visual Studio 2005 Command Prompt” and use
to examine the “wrong” DLL which will be produced on the 64-bit machine. You can compare it with the “good” DLL. I suppose that you will immediately see the differences. WinDiff.exe can help you additionally.
One small general advice: consider to use
EXTERN_CandWINAPI(or __stdcall) for all functions which you export from the DLL.