Witam serdecznie !
Mam problem z użyciem biblioteki napisanej lub przynajmniej kompatybilnej z BC++ w języku Delphi.
przykład kodu napisanego i działającego w BC++
bool __fastcall TForm1::PDI_Load()
{
bool bResult;
PdiLib = LoadLibrary ("Biblioteka.dll");
PF_PDI_Init_StandardRbg01 Pdi_Init;
Pdi_Init = (PF_PDI_Init_StandardRbg01) GetProcAddress(PdiLib, "PDI_Init_StandardRbg01");
Pdi_Init ("Plik_Konfigu","Test01", "1.00", "OFF",lResult);
deklaracja w pliku h
typedef void (*PF_PDI_Init_StandardRbg01) (char *, char *, char *, char *, long &);
pozostałe zmienne są podeklarowane w rożnych innych miejscach i nie maja większego znaczenia
Teraz to samo w Delphi (przynajmniej tak sadze)
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TPF_PDI_Init_StandardRbg01 = procedure (a : PAnsiChar; b : PAnsiChar; c : PAnsiChar; d : PAnsiChar;e :LongInt); cdecl;
TForm1 = class(TForm)
procedure FormShow(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
PdiLib: THandle;
end;
var
Form1: TForm1;
Pdi_Init: ^TPF_PDI_Init_StandardRbg01;
lResult : LongInt;
implementation
{$R *.dfm}
procedure TForm1.FormShow(Sender: TObject);
begin
PdiLib := LoadLibrary('Pdi.dll');
if PdiLib >= 32 then { success }
begin
Pdi_Init := GetProcAddress(PdiLib, 'PDI_Init_StandardRbg01');
lResult := lResult;
if Pdi_Init = nil then
MessageDlg('Error: Procedure name not exist !', mtError, [mbOk], 0)
end
else
MessageDlg('Error: could not find example DLL', mtError, [mbOk], 0)
// Pdi_Init('sdrgergrt','ergeggre', '1.00', 'OFF',lResult); <---- ta komenda nie chce się skompilować !
end;
end.
Po zamianie wskaznika ^TPF_PDI_Init_StandardRbg01 na TPF_PDI_Init_StandardRbg01 czyli zwykłą funkcję inne rzeczy przestają chodzi ale się kompiluje, oczywiście finalnie wywala błąd.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TPF_PDI_Init_StandardRbg01 = procedure (a : PAnsiChar; b : PAnsiChar; c : PAnsiChar; d : PAnsiChar;e :LongInt); cdecl;
TForm1 = class(TForm)
procedure FormShow(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
PdiLib: THandle;
end;
var
Form1: TForm1;
Pdi_Init: TPF_PDI_Init_StandardRbg01;
lResult : LongInt;
implementation
{$R *.dfm}
procedure TForm1.FormShow(Sender: TObject);
begin
PdiLib := LoadLibrary('Pdi.dll');
if PdiLib >= 32 then { success }
begin
Pdi_Init := GetProcAddress(PdiLib, 'PDI_Init_StandardRbg01');
lResult := lResult;
// if Pdi_Init = nil then <---- ta komenda nie chce się skompilować !
// MessageDlg('Error: Procedure name not exist !', mtError, [mbOk], 0)
end
else
MessageDlg('Error: could not find example DLL', mtError, [mbOk], 0)
Pdi_Init('sdrgergrt','ergeggre', '1.00', 'OFF',lResult);
end;
end.
Pytanie wiec są takie:
1 - Czy to się w ogóle da zrobić, dodam ze dll dla BC++ a pisze w BDelphi
2 - w przypadku gdy używam wskaźnika ^TPF_PDI_Init_StandardRbg01 czyli listing Delphi pierwszy, wszystko chodzi podobnie do C++, czyli ładuje bibliotekę, pobiera adres procedury "PDI_Init_StandardRbg01" itd.
Co jest dziwne to: to samo polecenie GetProcAddress daje rożne rezultaty w BC++ i BD ?? czemu ? Czy to ma znaczenie?
3 - główny problem z Drugim listingiem ze wywołuje: Access violation at address 1000C99A in module 'Biblioteka.dll'. Write of address 00000000.
4 - Natomiast pierwszy listing w Delphi nie daje możliwości skompilowania Pdi_Init() bo wywala błąd ;-(((
Myślę że pierwszy listing Delphi jest bliższy temu co zapisano w BC++, niemniej nie wiem co jest nie tak i czy to w ogóle ma szanse powodzenia ?
Pozdrawiam Szymon