DELPHI自定义结构体数组DLL传递

上周在解决上海二次开发的问题时,碰到了如下问题:

DELPHI7 函数原型

function SetDoorGuardPeriods(hPort: THandle; Fun: Byte; ts: array of TDoorTimePeriods;Count:Integer; week: Byte=0): Boolean;stdcall;

VC6 定义原型

typedef BOOL (PASCAL *ECSetDoorGuardPeriods)(HANDLE hPort, byte Fun,TDoorTimePeriods *ts,const int Count, const byte week=0);

BOOL bSuc = SetDoorGuardPeriods(m_hComHandle,Fun,ts,Count,week);

结果:样本 Vc6调用 :SetDoorGuardPeriods(1900,1,ts[1],1,0)

DLL传入 :1900,1,ts[2],13012481,96

问题 1 count \week两个数据不对

2 ts的长度与count相关 len(ts) = count+1

虽然找了很多的资料,但都不能很好的解释上叙问题,最后是在http://heng-feng.com.cn/programmer/mixprogramme/data3480764.html帮助下,

将VC定义修改为:

typedef BOOL (PASCAL *ECSetDoorGuardPeriods)(HANDLE hPort, byte Fun,TDoorTimePeriods &ts,int cnt, int Count, byte week);

这样的话,就能正常调用了。

问题出现的原因是DLL在取参数栈时,因为ARRORY的问题,多取了一个COUNT参数,导致此问题。