在开一贴(C#调用C的dll)高人们进来看下啊
原码:
typedef struct
{
long SeriaINo; //流水号
UCHAR ValidateTime[7]; //有效期
UCHAR IdentityCard[19]; //身份证号码
UCHAR ICCardNo[13]; //卡编号
UCHAR Name[17]; //姓名
UCHAR gender; //性别
}_Badic_Info;
int MakeCard(HANDLE icdev,LPCSTR psddword,_Basic_Info & Basic_Info,
ussigned long&CardSn)
用C#该怎么写
------解决方案--------------------public struct Badic_Info
{
int SeriaINo;
[MarshalAs(UnManagedType.ByValStr,SizeConst=7)]
string ValidateTime;
[MarshalAs(UnManagedType.ByValStr,SizeConst=19)]
string IdentityCard;
[MarshalAs(UnManagedType.ByValStr,SizeConst=13)]
string ICCardNo;
[MarshalAs(UnManagedType.ByValStr,SizeConst=17)]
string Name;
byte gender;
}
int MakeCard(IntPtr icdev,[MarshalAs(UnManagedType.ByLptStr)]string psddword,ref Basic_Info basic_Info, ref uint CardSn);
------解决方案--------------------大概觉得该这么写:
struct _Badic_Info
{
long SeriaINo; //流水号
string ValidateTime; //有效期
string IdentityCard; //身份证号码
string ICCardNo; //卡编号
string Name; //姓名
string gender; //性别
}
int MakeCard(long icdev,string psddword,ref _Basic_Info Basic_Info,
ref usigned long CardSn)
试试看
------解决方案--------------------改成:
MarshalAs(UnManagedType.LPTStr)]string psddword
------解决方案--------------------using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)]
public struct Basic_Info
{
[MarshalAs(UnmanagedType.U8)]
public string SeriaINo ;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=8)]
public string ValidateTime;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=20)]
public string IdentityCard;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=14)]
public string ICCardNo;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=18)]
public string Name;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=2)]
public string gender
}
------解决方案--------------------刚才写错了,sorry:
[StructLayout(LayoutKind.Sequential)]
public struct Basic_Info
{
[MarshalAs(UnmanagedType.U8)]
public long SeriaINo;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=8)]
public string ValidateTime;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=20)]
public string IdentityCard;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=14)]
public string ICCardNo;