- C/C++ code
像下面就没有问题:#pragma pack(1)typedef struct _SYSTEMTIME { WORD wYear; WORD wMonth; WORD wDayOfWeek; WORD wDay; WORD wHour; WORD wMinute; WORD wSecond; WORD wMilliseconds;} SYSTEMTIME, *PSYSTEMTIME, *LPSYSTEMTIME;typedef struct { CHAR com[10]; BYTE address;//地址 CHAR mcode[10];//组别 LONG code;//编号 CHAR start_time[4];//启动时间 LONG sAfter;//累计时间 LONG acc_count;//累计数量 SYSTEMTIME dt;//日期时间 }MAINDATA;#pragma pack()extern "C" {VOID WINAPI test(MAINDATA *p){ ::ZeroMemory(p,sizeof(MAINDATA)); ::CopyMemory(p->com,"ab",2); ::CopyMemory(p->mcode,"ab",2); p->acc_count=21; p->address=1; p->code=23; GetLocalTime(&p->dt); p->sAfter=53; ::CopyMemory(p->start_time,"abcd",4); }}PB:global type str_systemtime from structure uint wYear uint wMonth uint wDayOfWeek uint wDay uint wHour uint wMinute uint wSecond uint wMillisecondsend typeglobal type str_maindata from structure CHAR com[10]; BYTE address;//地址 CHAR mcode[10];//组别 LONG code;//编号 CHAR start_time[4];//启动时间 LONG sAfter;//累计时间 LONG acc_count;//累计数量 str_SYSTEMTIME dt;//日期时间end typesubroutine test(ref str_MAINDATA p) library "vscomm.dll" alias for "test;ansi"str_MAINDATA ptest(p)messagebox('',p.safter)当把dt改变位置其它不变就有问题,我也百思不得期解,如下:#pragma pack(1)typedef struct _SYSTEMTIME { WORD wYear; WORD wMonth; WORD wDayOfWeek; WORD wDay; WORD wHour; WORD wMinute; WORD wSecond; WORD wMilliseconds;} SYSTEMTIME, *PSYSTEMTIME, *LPSYSTEMTIME;typedef struct { CHAR com[10]; SYSTEMTIME dt;//日期时间 BYTE address;//地址 CHAR mcode[10];//组别 LONG code;//编号 CHAR start_time[4];//启动时间 LONG sAfter;//累计时间 LONG acc_count;//累计数量 }MAINDATA;#pragma pack()extern "C" {VOID WINAPI test(MAINDATA *p){ ::ZeroMemory(p,sizeof(MAINDATA)); ::CopyMemory(p->com,"ab",2); ::CopyMemory(p->mcode,"ab",2); p->acc_count=21; p->address=1; p->code=23; GetLocalTime(&p->dt); p->sAfter=53; ::CopyMemory(p->start_time,"abcd",4); }}PB:global type str_systemtime from structure uint wYear uint wMonth uint wDayOfWeek uint wDay uint wHour uint wMinute uint wSecond uint wMillisecondsend typeglobal type str_maindata from structure CHAR com[10]; str_SYSTEMTIME dt;//日期时间 BYTE address;//地址 CHAR mcode[10];//组别 LONG code;//编号 CHAR start_time[4];//启动时间 LONG sAfter;//累计时间 LONG acc_count;//累计数量 end typesubroutine test(ref str_MAINDATA p) library "vscomm.dll" alias for "test;ansi"str_MAINDATA ptest(p)messagebox('',p.safter)(只要dt不是放在最后,就有问题。以前我发现顺序问题,是因为内存对齐引起的;如今加了#pragma pack(1)来强制,还会出问题,还真想不透)
------解决方案--------------------
这个应该需要跟VC的顺序一致才行吧!
------解决方案--------------------
不同PB来调用,用其他语言来调用呢?