PInvoke, System.BadImageFormatException

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
 
J

James Park

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top