Delphi 2010:EOleSysError'类型不匹配'调用ActiveX控件

Ser*_*gio 5 delphi activex

我有这个C ActiveX API(没有源只是二进制文件):

// \param a [out] Variant holding a byte array 
// \param b [out] Reference to a longlong (Signed 64-bit)
// \param c [out] Reference to a short
short foo(variant* a, longlong* b, short* c);
Run Code Online (Sandbox Code Playgroud)

它在C#中运行良好:

//auto-generated import:   
short foo(ref object a, ref long b, ref short c);

test {
 object a=null;
 long b=0;
 short c=0;
 foo(a,b,c); => OK 
}
Run Code Online (Sandbox Code Playgroud)

Delphi 2010中的NOK(注意{?? Int64} OleVariant由Delphi导入工具添加):

//auto-generated import:
function foo(var a: OleVariant; 
             var b: {??Int64}OleVariant; 
             var c: Smallint): Smallint;

procedure Test;
var
 a, b: OleVariant;
 c: Smallint;
begin
 foo(a,b,c); => **EOleSysError 'Type mismatch' exception**
end;
Run Code Online (Sandbox Code Playgroud)

Ken*_*ite 1

您可以使用预定义的 WinAPI 类型:

// C definition
short foo(variant* a, longlong* b, short* c);

// Delphi definition
function foo(var a: OleVariant; 
             var b: LongLong; 
             var c: Smallint); Smallint;

procedure FooTest;
var
  a: OleVariant;
  b: LongLong;
  c, RetVal: ShmallInt;
begin
  Retval := foo(a, b, c);
end;
Run Code Online (Sandbox Code Playgroud)

LongLongWindows.pas与许多其他 WinAPI 兼容类型一起定义。(至少它们在WindowsDelphi XE 之前的单元中;由于跨平台和 64 位相关的重定位,XE2 可能已经重新定位了其中一些。)

// Windows.pas definition (Delphi 2010)
type
  LONGLONG = int64;
Run Code Online (Sandbox Code Playgroud)

正如 David 在下面的评论中不断提到的那样,longlong它不是标准的 C++ 数据类型。但是,根据与更新中的参数相关的注释,这正是C++ 开发人员的预期,因此 WinAPI 定义是兼容的(并保留相同的名称以保持文档一致性)。