I've been provided a C++ DLL that needs to be referenced in my C# project. The closest I've come to using that DLL yields an exception:
"Method's Type signature is not PInvoke compatible."
This is a simple DLL in that there is only a single method with a single input object and single output object. Both input and output objects are entirely Double and Int with a single boolean. Here is my code:
I try to call the Unit() method of the DLL like this:
I've ready so many topics on how to do this - there are so many different ways. I see many questions posted on this type of problem and I have read through each one. I'm totally lost on what it is I'm doing wrong or what I need to do additionally to make this work. Does anyone see what I need to do to make this work?
"Method's Type signature is not PInvoke compatible."
This is a simple DLL in that there is only a single method with a single input object and single output object. Both input and output objects are entirely Double and Int with a single boolean. Here is my code:
C#:
[StructLayout(LayoutKind.Sequential)]
public struct MyDLLInput
{
public int ProductModel;
public int Length;
public double Scale;
public int CalculationMethod;
[... additional double/int omitted for brevity ...]
};
C#:
[StructLayout(LayoutKind.Sequential)]
public struct MyDLLOutput
{
public int ProductModel;
public int Length;
public double Scale;
public int CalculationMethod;
public bool Warning_out_of_bounds;
public double version;
};
C#:
public class MYDLL
{
[DllImport("MyDLLProductSelector.dll",
EntryPoint="?Unit@@YA?AUMyDLLOutput@@UMyDLLInput@@@Z")]
public static extern MyDLLOutput Unit(MyDLLInput UnitInput);
}
I try to call the Unit() method of the DLL like this:
C#:
MyDLLInput myDllInput = new MyDLLInput();
MyDLLInput.ProductModel = 0;
MyDLLInput.Length = 0;
MyDLLInput.Scale = 85;
MyDLLInput.CalculationMethod = 85;
MyDLLOutput myDllOutput = MYDLL.Unit(myDllInput); <---- Exception thrown
C#:
"Method's Type signature is not PInvoke compatible."
I've ready so many topics on how to do this - there are so many different ways. I see many questions posted on this type of problem and I have read through each one. I'm totally lost on what it is I'm doing wrong or what I need to do additionally to make this work. Does anyone see what I need to do to make this work?