日期:2014-05-17 浏览次数:20757 次
struct AIS{
int type;
long mmsi;
float turn;
char status[10];
};
extern int _stdcall ReturnAIS(const char *buf,struct AIS* ais);
int _stdcall ReturnAIS(const char *buf,AIS *ais)
{
ais->type=11;
ais->mmsi=987654321;
ais->turn=11.1111;
strcpy(ais->status,buf);
return 0;
}
[StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct AIS
{
public int type;
public int mmsi;
public float turn;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 10)]
public string status;
//public byte[] status;
}
[DllImport("dlldemo.dll", EntryPoint = "ReturnAIS", CharSet = CharSet.Auto)]
public static extern int ReturnAIS(string buf, ref AIS ais);
//public static extern int ReturnAIS(char[] buf, ref AIS ais);
Console.WriteLine("---------------TEST ReturnAIS------------");
string status = "222222222";
CFuns.AIS aisout = new CFuns.AIS();
int r = CFuns.ReturnAIS(status,ref aisout);
Console.WriteLine("{0}\n{1}\n{2}\n{3}\n",aisout.type,aisout.mmsi,aisout.turn,aisout.status);
Console.ReadKey();