一
一飞冲天
Unregistered / Unconfirmed
GUEST, unregistred user!
procedure Tmain.getdll;
type
Tintfunc=function (AHandle: THandle;
ACaption: String;strUserId:string;
strMenuId:string): Longint;StdCall;
var
LibHandle,Ahandle:Thandle;
filepathcharChar;
showcalendar:Tshowcalendar;
Tp:Tfarproc;
Tf:tintfunc;
res:longint;
begin
// filepathchar:=pchar(FilePath);
LibHandle:=0;
LibHandle:=LoadLibrary('MS0102.DLL');
if LibHandle>0 then
try
Tp:=GetProcAddress(LibHandle,pchar('ShowDllFrm'));
if tp<>nil then
begin
Tf:=Tintfunc(tp);
res:=tf(Application.Handle,'ss','sss','fdfd');
application.Handle:=main.Handle;
end
else
ShowMessage('ShowDllFrm函数没有找到');
finally
FreeLibrary(LibHandle);
main.Show;
end
else
ShowMessage('dll没有找到');
end;
上面的代码是没问题的,但调用后出现问题!无法结束调用dll程序的线程!下面是我的dll代码
uses
SysUtils,
Classes,
ComObj,ActiveX,
DataModule in 'DataModule.pas' {DmFrm: TDataModule},
DLLFrm in 'DLLFrm.pas' {DLLForm},
PubUtils in 'PubUtils.pas';
{$R *.res}
exports
ShowDllFrm;
这也没什么问题哦呵呵,打开dll中的模块窗口的代码如下
implementation
Uses Datamodule,PubUtils, DBTables;
{$R *.DFM}
//参数:Ahandle:Thandle 传入调用本窗体的程序句柄;
//Acaption:string 传入本窗体的窗体标题,本例中没有使用
//以下的boolean变量可以根据自己的需要而增减,传入按钮控制
//
//返回值:Longint;
//
//==============================================================================
function ShowDllFrm(AHandle: THandle;
ACaption: String;strUserId:string;
strMenuId:string): Longint;
var
DLLForm: TDllForm;
//引用本窗体
begin
// Copy application handle to DLL's TApplication object
Application.Handle := AHandle;
//保存用户和菜单信息
sUserId:=strUserId;
sMenuId:=strMenuId;
InitEnv;
DLLForm := TDLLForm.Create(Application);
Result := Longint(DLLForm);
//以上的几句几乎不需改动
// DLLForm.Caption := ACaption;
DLLForm.ShowModal;
//显示该窗体
end;
调用没问题,但调用了后(执行了FreeLibrary)后,连main窗口(调用dll的窗口)也关闭了。但进程列表中还有该程序没有终止。如果加上application.destroy的话还是一样。请大虾指教
type
Tintfunc=function (AHandle: THandle;
ACaption: String;strUserId:string;
strMenuId:string): Longint;StdCall;
var
LibHandle,Ahandle:Thandle;
filepathcharChar;
showcalendar:Tshowcalendar;
Tp:Tfarproc;
Tf:tintfunc;
res:longint;
begin
// filepathchar:=pchar(FilePath);
LibHandle:=0;
LibHandle:=LoadLibrary('MS0102.DLL');
if LibHandle>0 then
try
Tp:=GetProcAddress(LibHandle,pchar('ShowDllFrm'));
if tp<>nil then
begin
Tf:=Tintfunc(tp);
res:=tf(Application.Handle,'ss','sss','fdfd');
application.Handle:=main.Handle;
end
else
ShowMessage('ShowDllFrm函数没有找到');
finally
FreeLibrary(LibHandle);
main.Show;
end
else
ShowMessage('dll没有找到');
end;
上面的代码是没问题的,但调用后出现问题!无法结束调用dll程序的线程!下面是我的dll代码
uses
SysUtils,
Classes,
ComObj,ActiveX,
DataModule in 'DataModule.pas' {DmFrm: TDataModule},
DLLFrm in 'DLLFrm.pas' {DLLForm},
PubUtils in 'PubUtils.pas';
{$R *.res}
exports
ShowDllFrm;
这也没什么问题哦呵呵,打开dll中的模块窗口的代码如下
implementation
Uses Datamodule,PubUtils, DBTables;
{$R *.DFM}
//参数:Ahandle:Thandle 传入调用本窗体的程序句柄;
//Acaption:string 传入本窗体的窗体标题,本例中没有使用
//以下的boolean变量可以根据自己的需要而增减,传入按钮控制
//
//返回值:Longint;
//
//==============================================================================
function ShowDllFrm(AHandle: THandle;
ACaption: String;strUserId:string;
strMenuId:string): Longint;
var
DLLForm: TDllForm;
//引用本窗体
begin
// Copy application handle to DLL's TApplication object
Application.Handle := AHandle;
//保存用户和菜单信息
sUserId:=strUserId;
sMenuId:=strMenuId;
InitEnv;
DLLForm := TDLLForm.Create(Application);
Result := Longint(DLLForm);
//以上的几句几乎不需改动
// DLLForm.Caption := ACaption;
DLLForm.ShowModal;
//显示该窗体
end;
调用没问题,但调用了后(执行了FreeLibrary)后,连main窗口(调用dll的窗口)也关闭了。但进程列表中还有该程序没有终止。如果加上application.destroy的话还是一样。请大虾指教