Libraries

Top  Previous  Next

What is translated > Libraries

 

Delphi2Cpp II can translate library files for Dll's like the following example from the Delphi help. It shows a DLL with two exported functions, Min and Max.

 

 

library MinMax;

 

function min(X, Y: integer): integer; stdcall;

begin

  if X < Y then min := X else min := Y;

end;

 

function max(X, Y: integer): integer; stdcall;

begin

  if X > Y then max := X else max := Y;

end;

 

exports

  min,

  max;

  

begin

end.

 

->

 

 

extern "C" __declspec(dllexport) int __stdcall max( int X, int Y );

extern "C" __declspec(dllexport) int __stdcall min( int X, int Y );

 

int __stdcall min( int X, int Y )

{

  int result = 0;

  if ( X < Y )

    result = X;

  else

    result = Y;

  return result;

}

 

int __stdcall max( int X, int Y )

{

  int result = 0;

  if ( X > Y )

    result = X;

  else

    result = Y;

  return result;

}

 

The Delphi help recommends: "If you want your DLL to be available to applications written in other languages, it’s safest to specify stdcall in the declarations of exported functions." However, the names of such exported functions get a special "decorated" signature in order to facilitate language features like overloading. To avoid such name mangling a module definition (.def-) file can be used in the Dll project. Delphi2Cpp II creates module definition files automatically.

 

 



This page belongs to the DelphiXE2Cpp11 Documentation

DelphiXE2Cpp11 home  Content