I have a dll created in c++ which exports function using the .def file.The function is written as follows:
__declspec(dllexport) int __stdcall MethodA(int par1,int par2,char *par3)
{....}
and then the method is declared in the .def file as
MethodA @1
Now my question is how can I use this method in my C# application ?
I tried adding the dll file as a reference in my C# application and I get the following message
"A reference to the filename.dll could not be added please make sure that the file is accessible and that the file is a valid assembly or COM component."
Edit:
After readings the comments posted here. I am attempting to use the file in the following manner
[DllImport("C:\\Filename.dll")]
public static extern int MethodA(int par1,int par2,String par3);
and the I am using it as such
MethodA(1,2,"SomeString);
This is the error I am getting
An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
While you did fine AFAIK on the C++ side, you need to do more on the C# side, You need to create a C# method declaration as something like this:
Decorate with
static,unsafeetc. as desired and needed.