DELPHI调用DLL函数出错
enli 2008-04-15 04:10:14 在DLL里面有一个函数,我是这样引用的:
function LIB_OPEN(ComName:PAnsiChar; EventID:longint;hWnd:Thandle):longint;stdcall; external 'DRIVER.dll';
这个是函数说明是这样的:
int __cdecl LIB_OPEN(LPCSTR ComName, int nEvtID,HWND hOwner)
然后我在程序里面这样调用的:
var temp:array[1..5] of char;
res:longint;
begin
TEMPADD :=0;
temp[1]:='C';
temp[2]:='O';
temp[3]:='M';
temp[4]:='2';
temp[5]:=char(0);
res := cct_lib_open(@temp,cct32_msg,frmmain.Handle);
end;
结果报出内存读取违例:access violation at address 007F063E.Read of address 007F07063E'
更奇怪的是:
我在后面加了输出就不报错了:修改调用如下:
TEMPADD :=0;
temp[1]:='C';
temp[2]:='O';
temp[3]:='M';
temp[4]:='2';
temp[5]:=char(0);
res := cct_lib_open(@temp,cct32_msg,frmmain.Handle);
if res <0 then
showmessage(inttostr(res));
请高手看看,我调用是不是有什么问题?我不输出的话为啥报错?