C++ 結構體數組回調C#代碼,c#數組只有一條

C# 方法code

[UnmanagedFunctionPointerAttribute(CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public delegate void RecvSwitchStatusCallback(string no, int noLength, IntPtr cpointer, int dataLength);string

public static void RequestRecvSwitchStatusCallback(string no, int noLength, IntPtr cpointer, int dataLength) {
IntPtr pointer = cpointer;
MyStruct[] listMyStruct = new MyStruct[dataLength];
int structSize = Marshal.SizeOf(typeof(MyStruct));
for (int i = 0; i < dataLength; ++i) {
var data = new IntPtr(pointer.ToInt64() + structSize * i);
MyStruct currentStruct = (MyStruct) Marshal.PtrToStructure(data, typeof(MyStruct));
listCommonLightStatus[i] = currentStruct;
}
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
public struct MyStruct {
public byte id;
public int code;
};it

[UnmanagedFunctionPointerAttribute(CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public delegate void RecvSwitchStatusCallback(string no, int noLength, IntPtr cpointer, int dataLength);io

相關文章
相關標籤/搜索