如何在C#中调用使用指针作为参数的DLL函数(C+;+;)?

如何在C#中调用使用指针作为参数的DLL函数(C+;+;)?,c#,c++,interop,pinvoke,dllimport,C#,C++,Interop,Pinvoke,Dllimport,我试图调用一个DLL函数(用C++编写),在C#中调用函数_a(Class1*input_类)。这是我在C#中声明的类。我读过关于在函数声明中使用ref关键字的内容,但我不确定。任何帮助都将不胜感激。谢谢 [DllImport("The_DLL.dll")] public static extern int Function_A(Class1* input_class); public struct Class1 { int varA; in

我试图调用一个DLL函数(用C++编写),在C#中调用函数_a(Class1*input_类)。这是我在C#中声明的类。我读过关于在函数声明中使用ref关键字的内容,但我不确定。任何帮助都将不胜感激。谢谢

[DllImport("The_DLL.dll")]
public static extern int Function_A(Class1* input_class);

public struct Class1
{
        int varA;
        int varB;
}

public struct Class2
{
        class1 class1_A;
        class1 class1_B;
}

static void Main(string[] args)
{
        Class2 a = new Class2();
        Function_A(...);
}

您需要知道
函数的调用约定在很大程度上取决于实际的类型。我们不知道,因为你没有包括它。
[DllImport("The_DLL.dll")]
public static extern int Function_A([In, Out]Class1 input_class);

[DllImport("The_DLL.dll", EntryPoint="Function_A")]
public static extern int Function_A2(ref Class1 input_class);


[StructLayout(LayoutKind.Sequential)]
public struct Class1 //a bad name for a struct but hey...
{
        int varA;
        int varB;
}


static void Main(string[] args)
{
        Class1 x = new Class1();
        Function_A(x); // your struct is marshalled so that changes by the external function are marshalled back
        Function_A2(x); // your struct is marshalled so that changes by the external function are NOT marshalled back
}