В настоящее время я работаю на USB-устройстве, которое получает данные с другого оборудования.
У меня проблема с typedef struct
, которую я не могу воспроизвести в c #.
В исходном коде от Dll у меня есть это:
typedef struct _UF01_INFORMATIONS{
BYTE Type[MAX_MODULE];
BYTE Nombre_Module;
BYTE Nb_Voies[MAX_MODULE];
BYTE Modele[MAX_MODULE];
char *Name[MAX_MODULE];
char *Comments[MAX_MODULE];
BOOL UseInterrupt;
} UF01_INFORMATIONS, *PUF01_INFORMATIONS;
MAX_MODULE equals 8 ^^
Это мой код:
[DllImport(@"C:\Program Files (x86)\DLL\UFDF.dll", EntryPoint = "UF01_OpenDevices", CallingConvention = System.Runtime.InteropServices.CallingConvention.Winapi)]
unsafe static extern Boolean UF01_OpenDevices(byte* devices);
[DllImport(@"C:\Program Files (x86)\DLL\UFDF.dll", EntryPoint = "UF01_CloseAll", CallingConvention = System.Runtime.InteropServices.CallingConvention.Winapi)]
unsafe static extern void UF01_CloseAll();
[DllImport(@"C:\Program Files (x86)\SELIAtec\DLL\UFDF.dll", EntryPoint = "UF01_UD01_8Entrees", CallingConvention = System.Runtime.InteropServices.CallingConvention.Winapi)]
unsafe static extern Boolean UF01_UD01_8Entrees(byte Device, byte module, byte* data);
[DllImport(@"C:\Program Files (x86)\DLL\UFDF.dll", EntryPoint = "UF01_UD01_8Entrees", CallingConvention = System.Runtime.InteropServices.CallingConvention.Winapi)]
unsafe static extern Boolean UF01_GetInfosModule(byte Device, bool Watchdog, [In, Out] _UF01_INFORMATIONS infos);
public Form1()
{
InitializeComponent();
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto, Pack = 1)]
public struct _UF01_INFORMATIONS
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
public unsafe byte[] Type;
[MarshalAs(UnmanagedType.I1)]
public unsafe byte Nombre_Module;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
public unsafe byte[] Nb_Voies;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
public unsafe byte[] Modele;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
public unsafe string[] Name;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
public unsafe string[] Comments;
[MarshalAs(UnmanagedType.I1)]
public unsafe bool UseInterrupt;
}
private unsafe void button1_Click(object sender, EventArgs e)
{
byte nb_Device;
_UF01_INFORMATIONS m_infos = new _UF01_INFORMATIONS();
m_infos.Type = new byte[8];
m_infos.Nb_Voies = new byte[8];
m_infos.Modele = new byte[8];
m_infos.Name = new string[8];
m_infos.Comments = new string[8];
m_infos.Nombre_Module = 0;
m_infos.UseInterrupt = false;
if (UF01_OpenDevices(&nb_Device))
{
this.label1.Text = "Nombre de CPU's : " + nb_Device;
UF01_GetInfosModule(nb_Device, false, m_infos); //<== Here is the ERROR
label2.Text = "Nombre de modules : " + m_infos.Nombre_Module;
}
}
Ошибка в строке «UF01_GetInfosModule»: «Управляемая подпись PInvoke не совпадает с неуправляемой»
Я ищу, но не могу найти причину этой ошибки.
Спасибо за вашу помощь!