0

我想在 WiringPi C 库中使用 mcp23017.c 中的函数创建一个 C #包装我将这个现有的 C# WiringPi WrapperClass用于其他功能。我想扩展这个包装类以使用 mcp23017 的函数。我尝试在包装器中创建一个具有一个函数的新类:

public class mcp23017
{

    [DllImport("libmcp23017.so", EntryPoint = "myPinMode")]
    public static extern void myPinMode(struct wiringPiNodeStruct *node,Int32 pin, Int32 mode);

}

但是我得到了 struct 元素的这些错误。

) expected.
; expected.
{ expected.
} expected.
Invalid token "*" in class struct or interface member declaration

我必须在包装类中定义一个结构吗?它是如何工作的?不熟悉这个,因为我是使用 C# 的新手。

4

1 回答 1

0

struct在 C# 中的参数上使用是无效的。编组器应该为您处理这种行为。也许你的意思是这样的。

[StructLayout(LayoutKind.Sequential)]
public struct WiringNode
{
    //Struct members here
}

[DllImport("libmcp23017.so", EntryPoint = "myPinMode")]
public static extern void myPinMode(ref WiringNode node, Int32 pin, Int32 mode);

然后称为:

var myStruct = new WiringStruct();
//Set struct members

myPinMode(ref myStruct, whatever, whatever);
于 2016-08-09T13:44:45.053 回答