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

发布于 2025-01-06 20:24:25 字数 829 浏览 2 评论 0原文

我有这个 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);

它在 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 
}

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;

I have this C ActiveX API (don't have the sources just the binaries):

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

It's working fine in 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 
}

NOK in Delphi 2010 (Note that {??Int64}OleVariant is added by the Delphi import tool):

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

囍孤女 2025-01-13 20:24:25

您可以使用预定义的 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;

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

// Windows.pas definition (Delphi 2010)
type
  LONGLONG = int64;

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

You can use predefined WinAPI types:

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

LongLong is defined in Windows.pas, along with many, many other WinAPI compatible types. (At least they're in the Windows unit up through Delphi XE; XE2 may have relocated some of them due to cross-platform and 64-bit related relocations.)

// Windows.pas definition (Delphi 2010)
type
  LONGLONG = int64;

As David keeps mentioning in the comments below, longlong isn't a standard C++ datatype. However, based on the comments related to the parameters in your update, it's exactly what the C++ developer intended it to be, and therefore the WinAPI definition is compatible (and retains the same name for consistency for documentation purposes).

椒妓 2025-01-13 20:24:25

longlong 不是标准 C++ 类型。我无法从 C++ 代码中判断出要使用什么类型。

现在,在我看来,使用 C# 工作更容易,其中类型比 C/C++ 更容易理解、更可靠。在 C# 中,long 是一个带符号的 64 位整数,因此在 Delphi 中是 Int64。问题中的 Delphi 代码片段中的其他两个参数指定正确。

longlong is not a standard C++ type. I can't tell from the C++ code what type to use.

Now, in my view it's easier to work from the C# where the types are more intelligible and reliable than C/C++. In C# long is a signed 64 bit integer, so Int64 in Delphi. The other two parameters in your Delphi snippet in the question are specified correctly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文