473,406 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 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 6694
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Andrea Palmieri | last post by:
hello everybody, I have to invoke a function defined in a c dll from a c# program, but I don't know the dll name at compile time. How do I declare and invoke this function using LoadLibrary and...
3
by: Madhu Gopinathan | last post by:
Hi, I am facing a problem in .NET COM InterOp. I have a COM Dll which I want to use from my CSharp code. So, I import the TLB directly from the DLL using the tlbimp tool to a managed DLL. I add a...
3
by: Installutil System.BadImageFormatExcepti | last post by:
I've tried to make a Windows Service using the 2005 C# and when I go to use Installutil it returns with an System.BadImageFormatException error while intializing the installation. I've even gone as...
4
by: Roger Aikin | last post by:
I've converted a VB6 project to VB.Net 2005. (Actually using vstudio pro 2005). I'm on a machine that also has VB6 and Vstudio.net 2003 on it. The project uses Word, Excel, MapPoint and SqlClient...
3
by: msnews.microsoft.com | last post by:
Hi i am using User32.dll in Visual stdio 2005. public static extern long SetActiveWindow(long hwnd); public static extern long keybd_event(byte bVk, byte bScan, long dwFlags,
6
by: Pucca | last post by:
I have a program that originally compiles into a exe file. I changed the compile option to generate dll file. This program calls a com component. Can I use pinvoke in C# to call it? The...
3
by: NickP | last post by:
Hi there, Today I try to compile an application of mine and I am getting a whole list of bizaar errors.... ------------------------------------------------ Error 1 The...
4
by: Glenn Palomar | last post by:
Hi, I have VB.net application that I recently migrated from VS2003 to VS2005. It works fine in Windows XP and 2K but NOT in XP64. I get an exception error that says...
0
by: kotti | last post by:
How to catch or rectify the System.badImageFormatException in c# while trying to debug the .cs file in Nunit.
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.