How to translate "array" param in C ++?

I am working on C ++ language bindings for our game engine (made with Delphi XE). How can I translate an array of OleVariant arrays and const parameters to work correctly on the C ++ side?

function  DLM_CallRoutine(const aFullname: PWideChar;
const aParamList: array of OleVariant): OleVariant; stdcall;

function  DLM_CreateObject(const aClassName: PWideChar;
const aParamList: array of const): Integer; stdcall;

Thank.

+3
source share
3 answers

Delphi has two completely separate array semantics that use the same code syntax array offor different purposes.

When array ofused to declare a data type or variable, it is used Dynamic Array, for example:

type
  TIntegerArray: array of Integer;

var
  Array1: TIntegerArray;
  Array2: array of Integer;

In C ++, they correspond to a template class DynamicArray<T>, for example:

typedef DynamicArray<int> TIntegerArray;

TIntegerArray Array1;
DynamicArray<int> Array2;

, array of (.. typedef), Open Array, :

procedure DoSomething(Arr: array of Integer);
procedure DoSomethingElse(Arr: array of const);

, Open Array, , - . Delphi , :

DoSomething([12345, 67890]);
DoSomethingElse(['Hello', 12345, True]);

++, , , , , OPENARRAY() ARRAYOFCONST(), :

// despite their names, the Size parameters are actually indexes.
// This misnaming has already been slated to be fixed in a future
// C++Builder release...
void __fastcall DoSomething(int const *Arr, const int Arr_Size);
void __fastcall DoSomethingElse(TVarRec const *Arr, const int Arr_Size);

DoSomething(OPENARRAY(int, (( 12345, 67890 )) );
DoSomethingElse(ARRAYOFCONST(( "Hello", 12345, true )) );
+3

Delphi. , Delphi, , Delphi, "", , Delphi, .

....

OLEVariant

, , ++ /, ( ), , "" Delphi RTL ( ).

, Fn ( OLEVariant) Delphi, Variant Array of Variant API ( -):

  Fn(array of OLEVariant)
  begin
    arr := VarArrayCreate(...);
    try
      // ... init arr from array of OLEVariant parameter

      // call actual API fn:
      APIFn(arr);

    finally
      // Dispose of variant array
    end;
  end;

Const

TVarRec ( , ). , "" Delphi - TVarRec ++.

, , . , , /, ?

Delphi API , ( const), , const . /, , const Delphi, -, TVarRec API.

+2

, Delphi . :

function  DLM_CallRoutine(const aFullname: PWideChar; 
          aParamList: POleVariant; numParams :integer): OleVariant; stdcall;

@A[0] Length(A) Delphi.

: memmory/ , OleVariant OLE. , .

Delphi

- Delphi , , System.pas SysUtils.pas. ( , ).

Delphi - :

type
  TDynArray = record
    refcount :integer;
    size:    :integer;
    content  :array[size*elementSize] of byte;
  end;

@A[0] , , @content. , refcount, .

C Delphi

, , C, Delphi dynarrays, Delphi? C , , , C :

  • .
  • .
  • API , , , . C- , .

API, C, API.

, .

+1

Source: https://habr.com/ru/post/1784281/


All Articles