VC 调用 delphi 写的一个 dll 导出函数,报栈溢出的异常的问题!
问题具体是这样的,厂家提供的一个用delphi写的一个dll,而我们公司的软件是用vc开发的,在调用一个delphi导出函数时报栈溢出,后来发现是这个导出函数的参数用了delphi的string,我自己又用delphi卦装了这个dll,把string换成pchar,但还是报栈溢出,有点要崩溃了,!delphi:
原厂家导出函数申明:
function purchasePower(comport: integer;
MeterType: integer;
userIDNo: string;
seq: integer;
purTimes: integer;
PurQty: double;
PurDate: string;
CmdByte: integer;
BalDate: integer;
WarnQty: double;
CoemptionQty: double;
PurPrice: double): integer; stdcall; far; external 'WS_4428_D6_SDDI.dll';
自己卦装函数导出:
function LP_PurchasePower(comport: integer;
MeterType: integer;
userIDNo: pchar;
seq: integer;
purTimes: integer;
PurQty: double;
PurDate: pchar;
CmdByte: integer;
BalDate: integer;
WarnQty: double;
CoemptionQty: double;
PurPrice: double): integer;stdcall;
begin
try
result:= purchasePower(comport,MeterType,userIDNo,seq,PurTimes,PurQty,
strPurDate,CmdByte,BalDate,WarnQty,coemptionQty,PurPrice);
except
result:= 1;
end;
end;
exports LP_PurchasePower;
VC调用delphi导出函数申明:
typedef int (__stdcall *PFunPurchasePower)(int iCom,int iMeterType,char*userIDNo,int iSeq,int iPurTimes, double dbPurQty,char* PurDate,int uCmdByte,int iBalDate, double dbWarnQty,double dbCoemptionQty,double dbPurPrice);
VC高用delphi导出涵数:
int CWSReader::PurchasePower(int iCom,int iMeterType,char* szUserIDNO,int iSeq,int iPurTimes,
double dbPurQty,char* szPurDate,int uCmdByte,int iBalDate,
double dbWarnQty,double dbCoemptionQty,double dbPrice)
{
if( m_hModule == NULL )
return -1;
PFunPurchasePower PPurchasePower = (PFunPurchasePower)GetProcAddress(m_hModule,"LP_PurchasePower");
if( PPurchasePower == NULL )
return -1;
int iRet = 0;
try
{
iRet = PPurchasePower(iCom,iMeterType,szUserIDNO,iSeq,iPurTimes,dbPurQty,szPurDate,uCmdByte,iBalDate,dbWarnQty,dbCoemptionQty,dbPrice);
}
catch (CMemoryException* e)
{
e->ReportError();
}
catch (CFileException* e)
{
e->ReportError();
}
catch (CException* e)
{
e->ReportError();
}
return iRet;
}
就算我把自己卦装的delphi导出函数改成以下不用VC传进来的参数,还是一样报错:
function LP_PurchasePower(comport: integer;
MeterType: integer;
userIDNo: pchar;
seq: integer;
purTimes: integer;
PurQty: double;
PurDate: pchar;
CmdByte: integer;
BalDate: integer;
WarnQty: double;
CoemptionQty: double;
PurPrice: double): integer;stdcall;
var
iPort:integer;
uMType:integer;
iSeq:integer;
iPurTimes:integer;
dbPurQty:double;
strUserIDNO:string;
strPurDate:string;
iCmdByte:integer;
iBalDate:integer;
dbWarnQty:double;
dbCQty:double;
dbPrice:double;
begin
try
//strPurDate:= '20140501';
//result:= purchasePower(comport,MeterType,userIDNo,seq,PurTimes,PurQty,
// strPurDate,CmdByte,BalDate,WarnQty,coemptionQty,PurPrice);
FillChar(strUserIDNO,sizeof(strUserIDNO),#0);
FillChar(strPurDate,sizeof(strPurDate),#0);
iPort:= 100;
uMType:= 16;
iSeq:= 1;
iPurTimes:= 31;
dbPurQty:= 2;
strUserIDNO:= '0106017592';
strPurDate:= '20140501';
iCmdByte:= 13;
iBalDate:= 1;
dbWarnQty:= 5;
dbCQty:= 999;
dbPrice:= -1;
result:= purchasePower(iPort,uMType,strUserIDNO,iSeq,iPurTimes,dbPurQty,strPurDate,iCmdByte,iBalDate,dbWarnQty,dbCQty,dbPrice);
except
result:= 1;
end;
end;