471,348 Members | 1,339 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,348 software developers and data experts.

PInvoke, System.BadImageFormatException

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

Jan 9 '06 #1
1 6556
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.

"cwjacklin" <cw*******@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
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

Jan 10 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Andrea Palmieri | last post: by
3 posts views Thread by Madhu Gopinathan | last post: by
3 posts views Thread by Installutil System.BadImageFormatExcepti | last post: by
3 posts views Thread by msnews.microsoft.com | last post: by
4 posts views Thread by Glenn Palomar | last post: by
1 post views Thread by Ronak mishra | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.