2 pièce(s) jointe(s)
communication avec une DLL ou ActiveX BOSCH
Bonjour,
Je ne suis pas débutant en Delphi mais je coince sur l'utilisation d'une DLL fourni par BOSCH.
J'ai besoin d'échanger avec un système de sécurité en entreprise. La société BOSCH fourni une DLL et une Activex écrits en C++.
Malgré de multiples essais (importation de l'ActiveX en composant, chargement dynamique en GetProcAdress ou statique avec déclaration en external) rien à faire, ou la compilation de mon programme se fait mais l'interface ne s'affiche pas ou j'ai des messages d'erreurs avec des EAcessViolation...
Si une âme charitable voulait bien venir à mon secours...
J'ai mis les sources BOSCH en pièces jointes.
Merci par avance
Mon code avec des essais des différentes méthodes :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
| unit BAPSI;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, BAPSIACTIVEXDLLNETLib_TLB;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
Const
nomDLL = 'D:\BAPSI source BOSCH\BAPSI\BAPSI\components\4.01.012\dll\BAPSIDLL.dll';
procedure Version(var version: WideString) cdecl; external nomDLL;
//nomOCX = 'D:\BAPSI source BOSCH\BAPSI\BAPSI\components\4.01.012\activex\BAPSIACTIVEXDLLNET.ocx';
//procedure GetVersion(var version: WideString) cdecl; external nomOCX;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
Type
TGetVersion = procedure (var Version : widestring;longueur : integer); cdecl;
TSetPort = procedure (Port : Integer); cdecl; // cdecl //stdcall
var result : bool;
Handle : THandle;
Version : TGetVersion;
SetPort : TSetPort;
chaine : widestring;
longueur : integer;
port : integer;
begin
//Handle := LoadLibrary('D:\BAPSI source BOSCH\BAPSI\BAPSI\components\4.01.012\activex\BAPSIACTIVEXDLLNET.ocx');
Handle := LoadLibrary('D:\BAPSI source BOSCH\BAPSI\BAPSI\components\4.01.012\dll\BAPSIDLL.dll');
if Handle <> 0 then
begin
@Version := GetProcAddress (Handle,'?Version@CBAPSIDLL@@QAEXPADH@Z');
if @Version <> nil then
begin
// Version (chaine,longueur);
Edit1.Text := chaine;
//FreeLibrary (Handle);
end
else
begin
ShowMessage ('Pb fonction GetVersion erreur '+IntToStr(GetLastError));
end;
@SetPort := GetProcAddress (Handle,'?SetPort@CBAPSIDLL@@QAEXH@Z');
if @SetPort <>nil then
begin
SetPort (port);
//FreeLibrary (Handle);
end
else
ShowMessage ('Pb fonction SetPort erreur '+IntToStr(GetLastError));
@Version := nil;
@SetPort := nil;
Application.ProcessMessages;
Freelibrary(Handle);
end
else
ShowMessage ('Pb Handle');
//Edit1.Text := BAPSIACTIVEXDLLNETLib_TLB.TBAPSIACTIVEXDLLNET.UnitName;
//BAPSIACTIVEXDLLNETLib_TLB.Register;
//result := BAPSIACTIVEXDLLNETLib_TLB. .SendMessageExist;
//BAPSIACTIVEXDLLNETLib_TLB.TBAPSIACTIVEXDLLNET.SendMessageExist;
//Edit2.Text := InttoStr(BAPSIACTIVEXDLLNETLib_TLB.BAPSIACTIVEXDLLNETLibMajorVersion);
end;
procedure TForm1.Button2Click(Sender: TObject);
var chaine_Version : widestring;
begin
//Version (chaine_version);
//GetVersion (chaine_Version);
end;
procedure TForm1.Button3Click(Sender: TObject);
var texte : WideString;
unc : widestring;
essai : BAPSIACTIVEXDLLNET;
begin
essai.Setdata(10,'99999999999999999999999999999999','BAPSI','10.149.0.202','4005');
Edit1.Text := inttostr(BAPSIACTIVEXDLLNETLibMajorVersion);
essai.SetUnc('10.149.0.202');
essai.GetVersion(texte);
GetVersion (texte);
TBAPSIACTIVEXDLLNET.SetUnc(unc);
end;
end. |