Solved

BadImageFormatException

Posted on 2009-07-14
2
541 Views
Last Modified: 2013-12-17
I am creating a c# program using a dll called GlobalVariable.dll in windows\system32.
I gave me an exception when I using a function within a dll. Can anyone tell me if there is more I need to setup the environment or tips how to resolve this problem. The code is the wrapper code the dll. The attachment is the snapshot during debugging.
using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Runtime.InteropServices;
 

namespace TSGlobalVariables

{

    public class TS

    {

        [DllImport("GlobalVariable.dll", EntryPoint = "GV_SetInteger")]

        public static extern int GV_SetInteger(int iLocation, int iVal);

        [DllImport("GlobalVariable.dll", EntryPoint = "GV_GetInteger")]

        public static extern int GV_GetInteger(int iLocation);

        [DllImport("GlobalVariable.dll", EntryPoint = "GV_SetDouble")]

        public static extern int GV_SetDouble(int iLocation, double dVal);

        [DllImport("GlobalVariable.dll", EntryPoint = "GV_GetDouble")]

        public static extern double GV_GetDouble(int iLocation);

    }

}

Open in new window

BadImageFormatException.jpg
0
Comment
Question by:xewoox
2 Comments
 
LVL 33

Accepted Solution

by:
Todd Gerbert earned 500 total points
ID: 24849317
The error message would seem to suggest your DLL is not really a DLL (or is a 64-bit DLL on a 32-bit system, or vice versa).

I Googled "BadImageFormatException" and first on the results list:

http://msdn.microsoft.com/en-us/library/system.badimageformatexception.aspx
This exception is thrown when the file format of a dynamic link library (.dll file) or an executable (.exe file) does not conform to the format that is expected by the common language runtime.
0
 

Author Closing Comment

by:xewoox
ID: 31603239
Good answer, right to the point.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now