111,128
社区成员
发帖
与我相关
我的任务
分享
typedef struct
{
BYTE BTR0;
BYTE BTR1;
BYTE AcceptFilterMode;
BYTE ACR[4];
BYTE AMR[4];
BYTE EMLR;
}PELICAN_PARAM_STRUCT, *pPELICAN_PARAM_STRUCT;
typedef struct
{
HDEVICE hCard;
BYTE CardId;
} ST_DEVDSC, *HDEVICE;
BOOL __stdcall AECCANC2_Init (HDEVICE hAECCANC2, BYTE ChanNo, pPELICAN_PARAM_STRUCT pPeliCanParam);
[StructLayout(LayoutKind.Sequential)]
public struct PELICAN_PARAM_STRUCT
{
public byte BTR0;
public byte BTR1;
public byte AcceptFilterMode;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
public byte[] ACR;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
public byte[] AMR;
public byte EMLR;
public PELICAN_PARAM_STRUCT(byte btr0, byte btr1, byte acceptFilterMode, byte emlr)
{
BTR0 = btr0;
BTR1 = btr1;
AcceptFilterMode = acceptFilterMode;
ACR = new byte[4];
AMR = new byte[4];
EMLR = emlr;
}
}
[StructLayout(LayoutKind.Sequential)]
public struct HDEVICE
{
public IntPtr hCard;
public byte CardId;
}
[DllImport("AECCANC2.dll")]
public static extern bool AECCANC2_Init(HDEVICE hAECCANC2, byte ChanNo, ref PELICAN_PARAM_STRUCT pPeliCanParam);
BOOL __stdcall AECCANC2_Open (HDEVICE *phAECCANC2, BYTE CardId);
[/quote]
你先试一下
[System.Runtime.InteropServices.DllImportAttribute("AECCANC2.dll", EntryPoint="AECCANC2_Open", CallingConvention=System.Runtime.InteropServices.CallingConvention.StdCall)]
[return: System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)]
public static extern bool AECCANC2_Open(ref System.IntPtr phAECCANC2, byte CardId) ;
[/quote]
感谢大神相助,确实是引用的问题。。。
C/C++的代码放到C#中就是各种恶心。。
BOOL __stdcall AECCANC2_Open (HDEVICE *phAECCANC2, BYTE CardId);
[/quote]
你先试一下
[System.Runtime.InteropServices.DllImportAttribute("AECCANC2.dll", EntryPoint="AECCANC2_Open", CallingConvention=System.Runtime.InteropServices.CallingConvention.StdCall)]
[return: System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)]
public static extern bool AECCANC2_Open(ref System.IntPtr phAECCANC2, byte CardId) ;
BOOL __stdcall AECCANC2_Open (HDEVICE *phAECCANC2, BYTE CardId);
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public struct PELICAN_PARAM_STRUCT {
/// BYTE->unsigned char
public byte BTR0;
/// BYTE->unsigned char
public byte BTR1;
/// BYTE->unsigned char
public byte AcceptFilterMode;
/// BYTE[4]
[System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst=4, ArraySubType=System.Runtime.InteropServices.UnmanagedType.I1)]
public byte[] ACR;
/// BYTE[4]
[System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst=4, ArraySubType=System.Runtime.InteropServices.UnmanagedType.I1)]
public byte[] AMR;
/// BYTE->unsigned char
public byte EMLR;
}
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public struct ST_DEVDSC {
/// HDEVICE->Anonymous_aa027289_d9d1_4a7b_8e4e_cf41a8b4b147*
public System.IntPtr hCard;
/// BYTE->unsigned char
public byte CardId;
}
方法
[System.Runtime.InteropServices.DllImportAttribute("AECCANC2.dll", EntryPoint="AECCANC2_Init", CallingConvention=System.Runtime.InteropServices.CallingConvention.StdCall)]
[return: System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)]
public static extern bool AECCANC2_Init(ref ST_DEVDSC hAECCANC2, byte ChanNo, ref PELICAN_PARAM_STRUCT pPeliCanParam) ;