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