主题:新手,各位大大帮忙看看,DLL中的参数传递问题?
对pb不是很熟悉,被要求改一个pb程序,是读卡器接口。
给了个delphi的例程,我仿照着改了,其中打开端口连接设备都没有问题,就是在读卡的时候发生参数传递错误:specified argument type differ from requirer argument type at runtime in dll function getcardid.(invalid stack pointer on return from function call)
delphi 的例程中是这样的:
interface
const
DLLNAME='ICRoom.dll';
Function OpenPort(hWnd:integer;strCommDef:string):integer;stdcall;external DLLNAME name 'OpenPort';
Function ClosePort():integer;stdcall;external DLLNAME name 'ClosePort';
Function ConnectDevice(nDevAddr:integer):integer;stdcall;external DLLNAME name 'ConnectDevice';
Function GetErrorMsg(ErrorCode:integer):string;stdcall;external DLLNAME name 'GetErrorMsg';
Function GetCardID(strCardID:PChar;var curBalance:double;nLen:integer):integer;stdcall;external DLLNAME name 'GetCardID';
Function ReduceCash(strCardID:string;curAmount:double):integer;stdcall;external DLLNAME name 'ReduceCash';
implementation
end.
var
code:integer;
scardid:pchar;
cardbalance:double;
begin
getmem(scardid,10);
cardbalance:=0;
code:=GetCardID(scardid,cardbalance,8);
end
我在pb中这样做:
function integer OpenPort(integer hWnd,string strCommDef) Library "ICRoom.dll"
function integer ClosePort() Library "ICRoom.dll"
function integer ConnectDevice(integer nDevAddr) Library "ICRoom.dll"
function string GetErrorMsg(integer ErrorCode) Library "ICRoom.dll"
function integer GetCardID(ref string strCardID,double curBalance,integer nLen) Library "ICRoom.dll"
function integer ReduceCash(string strCardID,double curAmount) Library "ICRoom.dll"
integer code
string scardid
double cardbalance
code = GetCardID(ref scardid,cardbalance,8)
if code=1 then
Messagebox('读卡成功','卡号:' + string(scardid) + ' 余额:'+ string(cardbalance))
else
Messagebox('读卡失败',GetErrorMsg(code))
end if
不知道该怎么改才好!! 这里先谢谢各位了!!!!!
给了个delphi的例程,我仿照着改了,其中打开端口连接设备都没有问题,就是在读卡的时候发生参数传递错误:specified argument type differ from requirer argument type at runtime in dll function getcardid.(invalid stack pointer on return from function call)
delphi 的例程中是这样的:
interface
const
DLLNAME='ICRoom.dll';
Function OpenPort(hWnd:integer;strCommDef:string):integer;stdcall;external DLLNAME name 'OpenPort';
Function ClosePort():integer;stdcall;external DLLNAME name 'ClosePort';
Function ConnectDevice(nDevAddr:integer):integer;stdcall;external DLLNAME name 'ConnectDevice';
Function GetErrorMsg(ErrorCode:integer):string;stdcall;external DLLNAME name 'GetErrorMsg';
Function GetCardID(strCardID:PChar;var curBalance:double;nLen:integer):integer;stdcall;external DLLNAME name 'GetCardID';
Function ReduceCash(strCardID:string;curAmount:double):integer;stdcall;external DLLNAME name 'ReduceCash';
implementation
end.
var
code:integer;
scardid:pchar;
cardbalance:double;
begin
getmem(scardid,10);
cardbalance:=0;
code:=GetCardID(scardid,cardbalance,8);
end
我在pb中这样做:
function integer OpenPort(integer hWnd,string strCommDef) Library "ICRoom.dll"
function integer ClosePort() Library "ICRoom.dll"
function integer ConnectDevice(integer nDevAddr) Library "ICRoom.dll"
function string GetErrorMsg(integer ErrorCode) Library "ICRoom.dll"
function integer GetCardID(ref string strCardID,double curBalance,integer nLen) Library "ICRoom.dll"
function integer ReduceCash(string strCardID,double curAmount) Library "ICRoom.dll"
integer code
string scardid
double cardbalance
code = GetCardID(ref scardid,cardbalance,8)
if code=1 then
Messagebox('读卡成功','卡号:' + string(scardid) + ' 余额:'+ string(cardbalance))
else
Messagebox('读卡失败',GetErrorMsg(code))
end if
不知道该怎么改才好!! 这里先谢谢各位了!!!!!