Constructor of TPaxInvoke class.constructor Create(AOwner: TComponent); override;
Destructor of TPaxInvoke class.destructor Destroy; override;
Loads dll and assigns address of a dll-defind functions to Address property.procedure LoadAddress(const DllName, ProcName: String);
Example
PaxInvoke1.This := nil; PaxInvoke1.CallConv := _ccMSFASTCALL; PaxInvoke1.LoadAddress('CppDll.dll', 'cube'); PaxInvoke1.ClearArguments; PaxInvoke1.AddArgAsInteger(2); PaxInvoke1.SetResultAsInteger; PaxInvoke1.CallHost; ShowMessage(IntToStr(Integer(PaxInvoke1.GetResultPtr^)));
Clears arguments.procedure ClearArguments;
Example
function TForm1.Test(X, Y: Integer): Integer; stdcall; begin result := X + Y; end; procedure TForm1.Button7Click(Sender: TObject); function P(X, Y: Currency): String; stdcall; begin result := CurrToStr(X + Y); end; begin PaxInvoke1.This := nil; // this is not a method PaxInvoke1.CallConv := _ccSTDCALL; PaxInvoke1.Address := @P; PaxInvoke1.ClearArguments; PaxInvoke1.AddArgAsCurrency(2.2); PaxInvoke1.AddArgAsCurrency(3.4); PaxInvoke1.SetResultAsAnsiString; PaxInvoke1.CallHost; // call host-defined function ShowMessage(String(PaxInvoke1.GetResultPtr^)); PaxInvoke1.ClearResult; PaxInvoke1.This := Self; // this is a method PaxInvoke1.CallConv := _ccSTDCALL; PaxInvoke1.Address := @TForm1.Test; PaxInvoke1.ClearArguments; PaxInvoke1.AddArgAsInteger(2); PaxInvoke1.AddArgAsInteger(3); PaxInvoke1.SetResultAsInteger; PaxInvoke1.CallHost; ShowMessage(IntToStr(Integer(PaxInvoke1.GetResultPtr^))); end;
Adds argument of Byte type.procedure AddArgAsByte(value: Byte);
Adds argument of Word type.procedure AddArgAsWord(value: Word);
Adds argument of Cardinal type.procedure AddArgAsCardinal(value: Cardinal);
Adds argument of ShortInt type.procedure AddArgAsShortInt(value: ShortInt);
Adds argument of SmallInt type.procedure AddArgAsSmallInt(value: SmallInt);
Adds argument of Integer type.procedure AddArgAsInteger(value: Integer);
Adds argument of Int64 type.procedure AddArgAsInt64(value: Int64);
Adds argument of LongBool type.procedure AddArgAsLongBool(value: LongBool);
Adds argument of WordBool type.procedure AddArgAsWordBool(value: WordBool);
Adds argument of Boolean type.procedure AddArgAsBoolean(value: Boolean);
Adds argument of Char type.procedure AddArgAsChar(value: Char);
Adds argument of WideChar type.procedure AddArgAsWideChar(value: WideChar);
Adds argument of Double type.procedure AddArgAsDouble(value: Double);
Adds argument of Single type.procedure AddArgAsSingle(value: Single);
Adds argument of Extended type.procedure AddArgAsExtended(value: Extended);
Adds argument of Currency type.procedure AddArgAsCurrency(value: Currency);
Adds argument of AnsiString type.procedure AddArgAsAnsiString(const value: AnsiString);
Adds argument of WideString type.procedure AddArgAsWideString(const value: WideString);
Adds argument of ShortString type.procedure AddArgAsShortString(const value: ShortString);
Adds argument of PChar type.procedure AddArgAsPChar(value: PChar);
Adds argument of PWideChar type.procedure AddArgAsPWideChar(value: PWideChar);
Adds argument of Pointer type.procedure AddArgAsPointer(value: Pointer);
Adds argument of a Record type.procedure AddArgAsRecord(var value; Size: Integer);
Adds argument of a record type. Argument is passed by value.procedure AddArgAsRecordByVal(var value; Size: Integer);
Adds argument of array type.procedure AddArgAsArray(var value; Size: Integer);
Adds argument of array type. Argument is passed by value.procedure AddArgAsArrayByVal(var value; Size: Integer);
Adds argument of a dynamic array type.procedure AddArgAsDynArray(var value);
Adds argument of a class type.procedure AddArgAsObject(value: TObject);
Adds argument of a class reference type.procedure AddArgAsClassRef(value: TClass);
Adds argument of Variant type.procedure AddArgAsVariant(const value: Variant);
Adds argument of a set type.procedure AddArgAsSet(var value; Size: Integer);
Adds argument of an interface type.procedure AddArgAsInterface(const value: IUnknown);
Sets result type as void type (for procedures).procedure SetResultAsVoid;
Sets result type as Byte type.procedure SetResultAsByte;
Sets result type as Word type.procedure SetResultAsWord;
Sets result type as Cardinal type.procedure SetResultAsCardinal;
Sets result type as ShortInt type.procedure SetResultAsShortInt;
Sets result type as SmallInt type.procedure SetResultAsSmallInt;
Sets result type as Integer type.procedure SetResultAsInteger;
Sets result type as Boolean type.procedure SetResultAsBoolean;
Sets result type as WordBool type.procedure SetResultAsWordBool;
Sets result type as LongBool type.procedure SetResultAsLongBool;
Sets result type as Char type.procedure SetResultAsChar;
Sets result type as WideChar type.procedure SetResultAsWideChar;
Sets result type as Double type.procedure SetResultAsDouble;
Sets result type as Single type.procedure SetResultAsSingle;
Sets result type as Extended type.procedure SetResultAsExtended;
Sets result type as Currency type.procedure SetResultAsCurrency;
Sets result type as AnsiString type.procedure SetResultAsAnsiString;
Sets result type as WideString type.procedure SetResultAsWideString;
Sets result type as ShortString type.procedure SetResultAsShortString;
Sets result type as PChar type.procedure SetResultAsPChar;
Sets result type as PWideChar type.procedure SetResultAsPWideChar;
Sets result type as a pointer type.procedure SetResultAsPointer;
Sets result type as an array type.procedure SetResultAsArray(Size: Integer);
Sets result type as a dynamic array type.procedure SetResultAsDynArray;
Sets result type as a record type.procedure SetResultAsRecord(Size: Integer);
Sets result type as a class type.procedure SetResultAsObject;
Sets result type as a class reference type.procedure SetResultAsClassRef;
Sets result type as an interface type.procedure SetResultAsInterface;
Sets result type as Int64 type.procedure SetResultAsInt64;
Calls a host-defined function or method.procedure CallHost;
Returns pointer to a result value.function GetResultPtr: Pointer;You have to apply the type cast to extract a result value.
Example
type TCharRec = record X, Y: Char; end; function MyHostFunc(const U, V: TCharRec): String; stdcall; begin result := U.X + V.Y; end; var R: TCharRec; S: String; begin R.X := 'a'; R.Y := 'b'; PaxInvoke1.Address := @ MyHostFunc; PaxInvoke1.This := nil; // this is not a method, but global function PaxInvoke1.ClearArguments; PaxInvoke1.AddArgAsRecord(R, SizeOf(R)); PaxInvoke1.AddArgAsRecord(R, SizeOf(R)); PaxInvoke1.SetResultAsAnsiString; PaxInvoke1.CallConv := _ccSTDCALL; PaxInvoke1.CallHost; // call host-defined function S := String(PaxInvoke1.GetResultPtr^); ShowMessage(S);
If result type is a dynamic type such as AnsiString, Interface, Variant or dynamic array, you have to apply the ClearResult method to avoid a memory leak.procedure ClearResult;
Example
type ITest = interface ['{E7AA427A-0F4D-4A96-A914-FAB1CA336337}'] procedure Proc(const S: String); end; TTest = class(TInterfacedObject, ITest) public procedure Proc(const S: String); end; procedure TTest.Proc(const S: String); begin ShowMessage(S); end; function GetIntf(I: ITest): ITest; begin if Assigned(I) then result := I else result := TTest.Create; end; var I, J: ITest; begin J := TTest.Create; PaxInvoke1.This := nil; // this is not a method PaxInvoke1.CallConv := _ccREGISTER; PaxInvoke1.Address := @GetIntf; PaxInvoke1.ClearArguments; PaxInvoke1.AddArgAsInterface(J); PaxInvoke1.SetResultAsInterface; PaxInvoke1.CallHost; // call host-defined function IUnknown(I) := IUnknown(PaxInvoke1.GetResultPtr^); I.Proc('hello'); PaxInvoke1.ClearResult; // IUnknown(PaxInvoke1.GetResultPtr^)._Release; end;