我有一个带接口的 DLL
struct modeegPackage
{
uint8_t version; // = 2
uint8_t count; // packet counter. Increases by 1 each packet
uint16_t data[6]; // 10-bit sample (= 0 - 1023) in big endian (Motorola) format
uint8_t switches; // State of PD5 to PD2, in bits 3 to 0
};
__declspec(dllexport) void __cdecl initSerial();
__declspec(dllexport) void __cdecl closeSerialPort();
__declspec(dllexport) struct modeegPackage __cdecl getPackage();
和 C# 适配器
class EEGCommunication
{
[StructLayout(LayoutKind.Sequential)]
public struct modeegPackage
{
/// unsigned char
public byte version;
/// unsigned char
public byte count;
/// unsigned int[6]
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 6, ArraySubType = UnmanagedType.U2)]
public UInt16[] data;
/// unsigned char
public byte switches;
}
private const string DLL = "libneureader-lib.dll";
[DllImport(DLL, EntryPoint = "_Z10initSerialv")]
public static extern void InitSerial();
[DllImport(DLL, EntryPoint = "_Z15closeSerialPortv")]
internal static extern void CloseSerialPort();
[DllImport(DLL, EntryPoint = "_Z10getPackagev", CallingConvention = CallingConvention.Cdecl)]
public static extern modeegPackage GetPackage();
}
但是当我尝试调用GetPackage
方法时,我收到一个错误Method's type signature is not PInvoke compatible.
我的代码有什么问题?
更新:代码更新