PInvoke, System.BadImageFormatException

  • Thread starter Thread starter cwjacklin
  • Start date Start date
C

cwjacklin

I read this article on
http://msdn.microsoft.com/msdnmag/issues/03/07/NET/
which describes how to invoke C win32 dll from C#

But I am running into a weird situation.

I have an existing C win32 dll which I want to call from C#. When I
use syntax like this

[DllImport("User32.dll")]
static extern Boolean MessageBeep(UInt32 beepType);
on my dll, I get an error 'System.BadImageFormatException'

However, if I just create from scratch a sample win32 dll in Visual
Studio, I can run the sample function just fine.

C# is supposed to be able to call a C unmanaged dll, but the error
seems to tell me otherwise.

Has anyone seen this before?

Thanks,

Jack
 
Are you using Windows x64? If your C# app is running as 64-bit and trying to
use a 32-bit dll, you'll get that exception.
 
Back
Top