Importowanie dll z C++ builder do Delphi

0

Stworzyłem w C++ Builderze bibliotekę dll:

//---------------------------------------------------------------------------
#include <vcl.h>
#include <windows.h>
#pragma hdrstop
//---------------------------------------------------------------------------
#pragma argsused
//---------------------------------------------------------------------------
double BoxArea(double L, double H, double W);
double BoxVolume(double L, double H, double W);

extern "C" __declspec(dllexport)void BoxProperties(double Length, double Height,
                                    double Width, double& Area, double& Volume);
//---------------------------------------------------------------------------
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
    return 1;
}
//---------------------------------------------------------------------------
double BoxArea(double L, double H, double W)
{
    return 2 * ((L*H) + (L*W) + (H*W));
}
//---------------------------------------------------------------------------
double BoxVolume(double L, double H, double W)
{
    return L * H * W;
}
//---------------------------------------------------------------------------
void BoxProperties(double L, double H, double W, double& A, double& V)
{
    A = BoxArea(L, H, W);
    V = BoxVolume(L, H, W);
}
//---------------------------------------------------------------------------

W ten sposób powstała biblioteka my_dll.dll
Dalej, chciałem ją wykorzystać w Delphi:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    Area,Volume: Real;
  end;

var
  Form1: TForm1;

procedure BoxProperties(L:real; H:real; W:real; var A:real; var V:real); stdcall; external 'my_dll.dll';

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
  BoxProperties(1,1,1,Area,Volume);
  Edit1.Text:=FloatToStr(Area);
end;

end.

Jednak podczas kompilacji wywala mi okno z błądem: "Nie znaleziono punktu wejścia procedury BoxProperties w bibliotece my_dll.dll"

Czym jest to spowodowane ??? Czy źle wywołuję procedurę ??
Pozdrawiam.
KOchzg

0

W Delphi pod koniec biblioteki dodaje się

exports
 Procedura name 'Procedura';
 //I tak dalej

Znajdź coś takiego do C++

0

Tutaj nie chodzi mi o tworzenie biblioteki dll w Delphi, tylko jak wykorzystać bibliotekę dll stworzoną w C++ Builder w Delphi.

Nie wiem gdzie popełniam błąd. Czy przy tworzeniu biblioteki czy w czytywaniu jej w Delphi.

0

Wiec rozwiązałem sobie problem.
Rozwiązanie piszę dla potomnych.
Jeżeli exportujemy funkcji w C++ Builderze w ten sposób:

extern "C" __declspec(dllexport) int __stdcall BoxProperties(int L, int H, int W);

to w Delphi odczytujemy ją w ten sposób z użyciem dyrektywty "stdcall":

function BoxProperties(L:integer; H:Integer; W:Integer): integer; stdcall; external 'my_dll.dll';

W przypadku gdy użyjemy tak:

extern "C" __declspec(dllexport) int BoxProperties(int L, int H, int W);

to musimy importować bibliotekę z dyrektywą "cdecl" czyli:

function _BoxProperties(L:integer; H:Integer; W:Integer): integer; cdecl; external 'my_dll.dll';

Jak widać nawet nazwa funkcji zmieniła się. W pierwszym przypadku jest bez "_".
Również w tym przypadku nie musimy się martwić z zwalnianiem ze stosu gdyż robi to za nas podprogram wywołujący.

A szczegóły możecie zobaczyć tutaj: http://wyw.dcweb.cn/stdcall.htm

Pozdrawiam
Kochzg

1 użytkowników online, w tym zalogowanych: 0, gości: 1