delphi.gif (306 バイト) DelphiからC++ Builderの関数を呼び出す


DelphiとC++ Builderのオブジェクトファイル(*.OBJ)は同じ形式なので、DLLを使わずに直接、C++ Builderで作った関数を呼び出すことができます。

 

CBuilder.gif (228 バイト)

extern "C" int _stdcall _export BcSquare(int);
extern "C" int _stdcall _export BcStrCmp(char *s);

int _stdcall BcSquare(int a)
{
  return (a * a);
}

int _stdcall BcStrCmp(char *s1, char *s2)
{
  return strcmp(s1, s2);
}

delphi.gif (306 バイト)

宣言

{$L BcbFunc1.obj} // $Lを使ってCBuilderで作ったObjファイルをリンクするように指示
function BcSquare(a: Integer): Integer; StdCall; external;
function BcStrCmp(s1: PChar; s2: PChar): Integer; StdCall; external;

使用例

var
a: Integer;
code: Integer;
s1: TBuffer;
s2: TBuffer;
p: Pointer;
begin

Val(txtInput.Text, a, code);
a := BcSquare(a);
txtResult.Text := IntToStr(a);

StrPCopy(s1, Edit1.Text);
StrPCopy(s2, Edit3.Text);
a := BcStrCmp(s1, s2);
Edit2.Text := IntToStr(a);