有一个第三方的vc写的dll,由于某种原因,该dll导出的函数都写成了cdecl的形式,所以我在delphi中也对应写了cdecl形式的调用声明,其中有一个函数是这样的:
void IsCapturing(int iCardID, BOOL* bIsCapturing);
我写成了:
procedure IsCapturing(iCardID:Integer;bIsCapturing:PBoolean);cdecl;
  external 'aa.dll' name 'IsCapturing';
可是当我用如下方法调用时,调用完后,程序总是出现莫明奇妙的异常。。地址访问失败之类的。调用如下:
var
  IsCapturing:Boolean;
begin
  IsCapturing(0,@IsCapturing);
  Result:=IsCapturing;
end;一开始我百思不得其解,后来尝试着写成这样:
var
  pIsCapturing:PBoolean;
begin
  new(pIsCapturing);
  IsCapturing^:=false;
  IsCapturing(0,pIsCapturing);
  Result:=pIsCapturing^;
  dispose(pIsCapturing);
end;
却一点问题都没有了,我在想是不是delphi对变量进行了优化的结果阿??希望高手指点

解决方案 »

  1.   

    我想还是那个IsCapturing的问题,它是在dll里面的么?(它的内存的分配)
      

  2.   

    对阿,它是别人用vc写的dll中的一个导出函数,我没有原代码。。
    我觉得可能和它使用cdecl有关。。
      

  3.   

    procedure IsCapturing(iCardID:Integer;bIsCapturing:PBoolean);cdecl;
      external 'aa.dll' name 'IsCapturing';
    //??????????
    var
      IsCapturing:Boolean;//??????????
    begin
      IsCapturing(0,@IsCapturing);
      Result:=IsCapturing;
    end;//一样?????????
      

  4.   

    倒……BOOL可是4字节的啊!Boolean 1字节,这样怎么会不错呢?写成:Uses
        Windows, Types, ...;Procedure IsCapturing(iCardID:Integer; Var bIsCapturing: BOOL); CDecl; External 'aa.dll' Name 'IsCapturing';
    或者
    Procedure IsCapturing(iCardID:Integer; Var bIsCapturing: LongBool); CDecl; External 'aa.dll' Name 'IsCapturing';顺便问一下,你在用哪块捕捉卡啊?好眼熟……