Delphi 2010:EOleSysError“类型不匹配”调用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);
它在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用预定义的 WinAPI 类型:
LongLong
是在Windows.pas
中定义的,以及许多其他 WinAPI 兼容类型。 (至少它们在 Delphi XE 之前的Windows
单元中;由于跨平台和 64 位相关的重定位,XE2 可能已经重新定位了其中一些。)正如 David 在下面的评论中不断提到的那样,
longlong
不是标准 C++ 数据类型。但是,根据与更新中的参数相关的注释,它完全正是 C++ 开发人员的预期,因此 WinAPI 定义是兼容的(并保留相同的名称以保持文档一致性)。You can use predefined WinAPI types:
LongLong
is defined inWindows.pas
, along with many, many other WinAPI compatible types. (At least they're in theWindows
unit up through Delphi XE; XE2 may have relocated some of them due to cross-platform and 64-bit related relocations.)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).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, soInt64
in Delphi. The other two parameters in your Delphi snippet in the question are specified correctly.