Delphi 2010: EOleSysError "Mismatch Type" Invoking ActiveX Control

I have this C ActiveX API (you have no sources of binary files only):

// \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 works 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;
+5
source share
2 answers

You can use the 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;

LongLongdefined in Windows.pas, along with many, many other WinAPI-compatible types. (At least they are in the module Windowsthrough Delphi XE, XE2, they may have moved some of them due to cross-platform and 64-bit related moves.)

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

, LongLong ++. , , , ++, WinAPI ( ).

+1

longlong ++. ++, .

, , #, , C/++. # long 64- , Int64 Delphi. Delphi .

+1

All Articles