阿
阿群
Unregistered / Unconfirmed
GUEST, unregistred user!
DLL代码如下:
library Login;
{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }
uses
SysUtils,
Windows,
Forms,
Controls,
MConnect,
SConnect,
//DBClient,
Classes,
LoginU in '../SysSetup/LoginU.pas' {frmLogin};
{$R *.res}
Function ShowLoginForm(app:TApplication;SocketCon:TSocketConnection;IniPath:string;var IsTrial:boolean;
var UserName,usepawd:LPSTR):boolean;stdcall;
var
p:^LongInt;
begin
p:=@(Application.MainForm);
p^:=LongInt(app.MainForm);
Frmlogin := TFrmlogin.Create(app);
Frmlogin.SocketCon:=SocketCon;
Frmlogin.IniPath:=IniPath;
if Frmlogin.ShowModal = mrOK then
begin
IsTrial:=Frmlogin.IsTrial;
UserName:=pchar(FrmLogin.UserName);
usepawd:=pchar(FrmLogin.usepawd);
Result := true;
end
else
Result := False;
end;
exports
ShowLoginForm;
begin
end.
调用DLL代码如下:
var
BaseDataDMF: TBaseDataDMF;
implementation
uses GlobalU;
Function ShowLoginForm(app:TApplication;SocketCon:TSocketConnection;IniPath:string;var IsTrial:boolean;var UserName,usepawd:LPSTR):boolean;stdcall;external 'Login.dll';
{$R *.dfm}
function TBaseDataDMF.Login: Boolean;
var IsTrial:boolean;
UserName,usepawd:LPSTR;
begin
result:=ShowLoginForm(Application,SocketConnection,extractfilepath(application.ExeName),IsTrial,UserName,usepawd);
if result then
begin
GlobalData.IsTrial:=IsTrial;
GlobalData.UserName:=String(UserName);
GlobalData.usepawd:=String(usepawd);
end;
end;
问题是:第一次调用Login不会有问题,第二次在程序中调用的时候出现访问login.dll的无效地址错误,不解?
library Login;
{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }
uses
SysUtils,
Windows,
Forms,
Controls,
MConnect,
SConnect,
//DBClient,
Classes,
LoginU in '../SysSetup/LoginU.pas' {frmLogin};
{$R *.res}
Function ShowLoginForm(app:TApplication;SocketCon:TSocketConnection;IniPath:string;var IsTrial:boolean;
var UserName,usepawd:LPSTR):boolean;stdcall;
var
p:^LongInt;
begin
p:=@(Application.MainForm);
p^:=LongInt(app.MainForm);
Frmlogin := TFrmlogin.Create(app);
Frmlogin.SocketCon:=SocketCon;
Frmlogin.IniPath:=IniPath;
if Frmlogin.ShowModal = mrOK then
begin
IsTrial:=Frmlogin.IsTrial;
UserName:=pchar(FrmLogin.UserName);
usepawd:=pchar(FrmLogin.usepawd);
Result := true;
end
else
Result := False;
end;
exports
ShowLoginForm;
begin
end.
调用DLL代码如下:
var
BaseDataDMF: TBaseDataDMF;
implementation
uses GlobalU;
Function ShowLoginForm(app:TApplication;SocketCon:TSocketConnection;IniPath:string;var IsTrial:boolean;var UserName,usepawd:LPSTR):boolean;stdcall;external 'Login.dll';
{$R *.dfm}
function TBaseDataDMF.Login: Boolean;
var IsTrial:boolean;
UserName,usepawd:LPSTR;
begin
result:=ShowLoginForm(Application,SocketConnection,extractfilepath(application.ExeName),IsTrial,UserName,usepawd);
if result then
begin
GlobalData.IsTrial:=IsTrial;
GlobalData.UserName:=String(UserName);
GlobalData.usepawd:=String(usepawd);
end;
end;
问题是:第一次调用Login不会有问题,第二次在程序中调用的时候出现访问login.dll的无效地址错误,不解?