I'm using delphi4
Could someone help me?!
Here's the code:
procedure tform1.connect;
var
//for the loading of the dll
LibHandle: THandle;
pPath : pchar;
loginDB : function (var AServer, ADatabase, AUser, APassword,
AODBCAlias, ASQLServerType: Pchar; Database : pointer) : Integer; stdcall;
//as it name tell
loginResult : Integer;
// var passed to the dll
AServer, ADatabase, AUser, APassword, AODBCAlias, ASQLServerType : Pchar;
begin
try
try
pPath :=
pchar(extractfilepath(application.exename)+'loginDlg.dll');
LibHandle := LoadLibrary(pPath);
if LibHandle = 0 then
begin
messagedlg('Contact your dealer', mtInformation,[mbOk],0);
exit;
end else
begin
loginDB := GetProcAddress(Libhandle, 'loginDB');
AODBCAlias := pchar(Database.AliasName);
ASQLServerType:= 'SQL Server';
loginResult:= loginDB(AServer,ADatabase,AUser,APassword,
AODBCAlias, ASQLServerType,nil);
//error on logon
if loginResult=-1 then
begin
raise Exception.Create('You must connect to database first
!');
end else if loginResult > -1 then
begin
Database.Params.Add('USER NAME= '+AUser);
Database.Params.Add('PASSWORD='+APassword);
Database.Connected:=true;
end else if loginResult = -2 then
begin
//on cancel button click
Application.ProcessMessages;
Application.Terminate;
end;
end;
except
on exception do raise;
end;
finally
if LibHandle <> 0 then
begin
try
FreeLibrary(LibHandle);
except
on exception do raise;
end;
end;
end;
LibHandle := LoadLibrary(
pchar(extractfilepath(application.exename)+'loginDlg.dll') );
Lucian
procedure LoadDLL;
const
DLLName = 'MyDll.DLL';
type
TMyFunction : function (par1, par2 : Integer); stdcall;
var
HInst : THandle;
FPointer : TFarProc;
MyFunct : TMyFynction (par1, par2 : Integer);
Loginresult : Integer;
begin
HInst := LoadLibrary('THEDLLPATH' + DLLName);
if HInst > 0 then
try
FPointer := GetProcAddress(HInst, 'MyFunction');
if FPointer <> nil then
begin
MyFunct := TMyFunction(FPointer);
Loginresult := MyFunct (a, b); {for example}
end
else MessageDlg('Could not find function', mtError, [mbOK], 0);
finally
FreeLibrary(HInst);
end
else MessageDlg('Could not find library (DLL)', mtError, [mbOK], 0);
end;
CMAD
PS. It would be better if you do what you want with the DLL (in the middle
of the program the begin-end).
"simon carrier" <mano...@sympatico.ca> wrote in message
news:3cfe573c_2@dnews...