DllImport - Method's Type signature is not PInvoke compatible

rwkiii

New member
Joined
Jul 8, 2014
Messages
2
Programming Experience
10+
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:

Code:
[StructLayout(LayoutKind.Sequential)]
    public struct MyDLLInput
    {
    public int ProductModel;
             public int Length;
             public double Scale;
             public int CalculationMethod;

             [... additional double/int omitted for brevity ...]

   };
Code:
[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;
    };
Code:
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:

Code:
MyDLLInput myDllInput = new MyDLLInput();

         MyDLLInput.ProductModel = 0;
         MyDLLInput.Length = 0;
         MyDLLInput.Scale = 85;  
         MyDLLInput.CalculationMethod = 85;
            
         MyDLLOutput myDllOutput = MYDLL.Unit(myDllInput);   <---- Exception thrown

Code:
"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?
 

rwkiii

New member
Joined
Jul 8, 2014
Messages
2
Programming Experience
10+
What's up with that funky EntryPoint value? I don't use much unmanaged code but I've never seen something like that.
Agree completely, but apparently there is a term for it called "mangling". Has something to do with the way C++ or unmanaged DLLs do things. I know it doesn't look right, but that's the way it shows up using Dependency Walker (Dependency Walker (depends.exe) Home Page).
 
Top Bottom