Ok then, i made what you told me to do and I'm not getting an error anymore but a memory leak persists. here is the complete source code and ckeck when FreeLibrary executes, I did load and unload the MSDll 5 times and this is my memory lost:
1st unload: 144 Kb
2nd unload: 172 Kb
3rd unload: 152 Kb
4th unload: 152 Kb
5th unload: 148 Kb
--------------------------------------------------------------------------------
SOURCE CODE
--------------------------------------------------------------------------------
MSDllLoader:
---------
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1 : TForm1;
HandleDll : THandle;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
type
Entrada_ = function: Integer;
var
FEntrada : Entrada_;
REntrada : TFarProc;
begin
HandleDll := LoadLibrary(PChar('MSDll.dll'));
if HandleDll > 0 then
begin
REntrada := GetProcAddress(HandleDll,PChar('Entrada'));
FEntrada := Entrada_(REntrada);
FEntrada;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
type
LiberaMemoria_ = function: Integer;
var
FLiberaMemoria : LiberaMemoria_;
RLiberaMemoria : TFarProc;
begin
if HandleDll > 0 then
begin
RLiberaMemoria := GetProcAddress(HandleDll,PChar('LiberaMemoria'));
FLiberaMemoria := LiberaMemoria_(RLiberaMemoria);
FLiberaMemoria;
FreeLibrary(HandleDll);
end;
end;
end.
--------
MDDll:
--------
library MSDll;
uses
SysUtils,
Classes,
Windows,
MSAccess,
Dialogs,
ActiveX;
{$R *.RES}
var
Query : TMSQuery;
Conexion : TMSConnection;
function Entrada: Integer;
begin
try
CoInitialize(nil);
Query := TMSQuery.Create(nil);
Conexion := TMSConnection.Create(nil);
Conexion.ConnectString := 'Provider=SQLOLEDB.1;User ID=sa;Data Source=(local);Initial Catalog=TCADBPRU;Use Encryption for Data=0';
Conexion.LoginPrompt := False;
Conexion.Connected := True;
except
on E: Exception do
showmessage(E.Message);
end;
Result := 0;
end;
function LiberaMemoria: Integer;
var
ren : String;
begin
try
ren := '1';
Conexion.Close;
ren := '2';
Conexion.Free;
ren := '3';
Query.Free;
ren := '4';
CoUninitialize;
ren := '5';
except
on E: Exception do
showmessage(E.Message+#13+'Ren: '+Ren);
end;
Result := 0;
end;
exports
Entrada,LiberaMemoria;
end.
-------
Hope you can help me, I buy your components already under
[email protected] user