Re: BadImageFormatException
Fancy posting some more code?
matt
Re: BadImageFormatException
this is the example i used.... I am using visualstudio 2005 ...created the dll using win32 dll wizard.
<code>
mydll.h
int AddInt(int a , int b);
mydll.cpp
#include <stdio.h>
#include "mydll.h"
int AddInt(int a, int b){
int c;
c=a+b;
return c;
}
c# file
using System.Runtime.InteropServices;
using System;
class callDll{
[DllImport("<fullpathname>mydll.dll")]
private static extern int AddInt(int a, int b);
public static void Main() {
int aa = 100;
int bb= 150;
int cc;
cc=AddInt(aa, bb);
Console.WriteLine("Value returned is "+cc);
}
}
</code>
This is a simple program, though i am not doing any useful in here, i want to understand the concept of calling c++ dll from c# as i have a bigger project to work on.
All the files compile fine... no errors. Only at runtime, when to comes to call cc=AddInt(aa,bb) it errors with BadImageFormatException.
Thanks for your reply.
Re: BadImageFormatException
Re: BadImageFormatException
Next time use those: [CODE [/CODE (with ] in the end of the [/CODE & [CODE)...
emm.. I don't know what's the problem, but you can do this:
instead:
Code:
int c;
c=a+b;
return c;
Sorry :/
Re: BadImageFormatException
Thanks for you reply..
i don't think the problem is with the way the value is returned.
Have i done everything right in the c# program? Why is the dll in badimageformat.....? any clues?
Re: BadImageFormatException
Re: BadImageFormatException
Rachael,
i dont think you can call the c++ code directly from c#. You need to create a CLR project to interface with the C++ project. Then you need to call the CLR project from C#. The CLR project will call the C++ code.
Re: BadImageFormatException
Quote:
Originally Posted by
jobin1983
Rachael,
i dont think you can call the c++ code directly from c#. You need to create a CLR project to interface with the C++ project. Then you need to call the CLR project from C#. The CLR project will call the C++ code.
this is not about thinking but about knowing... if you don't know don't post such nonsense :sick:
sure you can call native code from C#.
now to OP: I have still a similar problem http://www.codeguru.com/forum/showth...ormatException
though the post is quite old the same error comes. what's more, it happens to my own wrapper that I cannot use in C# because of this stupid error. there are no clues how to solve it.
I don't think anybody will be able to help us. this must be a very very very rare issue and no one ever has seen it ;)