用VC写的一个ATL,在Delphi6中调用时:VC中的接口:
[id(1), helpstring("method GetID")] HRESULT GetID([in]long n1, [in]long n2, [out, retval]long* pVal); 
通过Import Type Library生成的*.TLB文件中:
有时候生成:
...
function GetID(n1: Integer; n2: Integer; out pVal: Integer): HResult; stdcall; //调用正确
...
而有时候生成:
...
function GetID(n1: Integer; n2: Integer): integer; stdcall; //调用出错
...
不知是为什么。

解决方案 »

  1.   

    按照delphi生成的接口标准,应该是第一种声明,这也是微软的标准定义。建议楼主使用标准的定义,以免出现这种问题
      

  2.   

    接口定义是在VC中定义的,我的疑惑是同一种定义(IDL文件确实没有变化)下,
    通过Import   Type   Library自动生成的*.TLB文件中为什么有时候是:
      IBillOpr = interface(IDispatch)
        ['{34E6BBDA-ACE9-47CD-A0FB-A731020004B2}']
        ...
        function GetID(n1: Integer; n2: Integer; out pVal: Integer): HResult; stdcall;//能正确调用
       ...
      end;而有时候是:
    IBillOpr = interface(IDispatch)
        ['{34E6BBDA-ACE9-47CD-A0FB-A731020004B2}']
        ...
        function GetID(n1: Integer; n2: Integer): integer; stdcall;//该种情况下会产生“找不到组件”错误
       ...
      end;
    呢。