我是菜鸟,stdcall的偏差

用了N年的DELPHI的我遇到这个后发现,自己真是菜鸟
我把问题提到CSDN后:

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));

请高手看看,我调用是不是有什么问题?我不输出的话为啥报错?

发表于:2008-04-15 16:26:401楼 得分:0
声明是cdecl,引用也应该是cdecl而不是stdcall吧


其实就这么简单,唉。。。。。还要努力啊!
posted @ 2008-04-15 16:45  Enli  阅读(288)  评论(1编辑  收藏  举报