如何在DLL中关闭调用的程序??????请近来看。 我有一个DLL,这个DLL中包含一个窗口,一个按钮,我在程序中调用这个dll,如何实现点击按钮,这个调用dll的程序可以实现关闭。如何传递消息呀??????? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 把你的调用dll的程序的窗体名传入 MyHandle:=FindWindow('FormName',''); if MyHandle<>0 then PostMessage(MyHandle,wm_close,0,0); 看看下面的文章,应该能够解决你的问题一.函数过程的写法:library FIRSTDLL;uses SysUtils, Classes;{$R *.RES}// 1.定义函数具体过程和输出接口方式// --------------------------------// 函数 1// 功能:事数据3倍放大函数// --------------------------------function PenniesToSoins(SourceResult:Integer):Integer;stdCall;begin if SourceResult>0 then Result:=SourceResult*3 //结果存放于Result else Result:=SourceResult;end;exports PenniesToSoins; //2.函数输出口定义end.====二.在DLL中创建Form=======================1.一步,创建DLL工程,及加入设置好的Formlibrary MGRPERSN;uses SysUtils, Classes, MGRPERFM in 'MGRPERFM.pas' {FormPERSON};//1.Form的代码(与一般的Form一样){$R *.RES}exports ShowPerSN;//2.函数输出口定义beginend.2. 在DLL设定的Form的设置 ===========================================unit MGRPERFM;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ComCtrls, ToolWin, ImgList;type TFormPERSON = class(TForm) private { Private declarations } public { Public declarations } end;//些处的变量不再用,给其改个地方,如下(改变之一)//var // FormPERSON: TFormPERSON;{ Declare the export function 宣布Form函数出口}//改变之二function ShowPerSN(AHandle: THandle; ACaption: String):BOOL; StdCall;implementation{$R *.DFM}//函数据过程定义function ShowPerSN(AHandle: THandle; ACaption: String):BOOL;var FormPERSON: TFormPERSON; //定义窗体类(上面的放到了此处)begin // Copy application handle to DLL's TApplication object //拷贝应用程式句柄给DLL的应有程式对象 Application.Handle := AHandle; FormPERSON := TFormPERSON.Create(Application);//创建控件TForm try FormPERSON.Caption := ACaption; FormPERSON.ShowModal;//显示此Form // Pass the date back in Result Result := False; //反回成功值 finally FormPERSON.Free; end;end;三.DLL中函数及窗体的调用==========================1.调用方法一--------------implementation //在此的下方写明调用函数的DLL{$R *.DFM}//DLL内函数调用function PenniesToSoins(SourceResult:Integer):Integer; StdCall external 'FIRSTDLL.DLL';........2.调用方法二==============type //在此创建一个函数类 // 1 ------------------------------- { First, define a procedural data type, this should reflect the procedure that is exported from the DLL. } { Create a new exception class to reflect a failed DLL load } TShowPerSN = function (AHandle: THandle; ACaption: String): BOOL; StdCall; EDLLLoadError = class(Exception);//同时分创建一个出错记录类 // 1 ------------------------------- TMAINCLTR = class(TForm) //这里不变,系统自动生成......procedure TMAINCLTR.ToolButton1Click(Sender: TObject);var //按钮的调用事件:调用过程 LibHandle: THandle; ShowPerSN: TShowPerSN;begin Application.Title:='人力资源管理系统DLL文件测试程式'; { Attempt to load the DLL 尝试装入DLL文件} LibHandle := LoadLibrary('MGRPERSN.DLL'); try if LibHandle = 0 then raise EDLLLoadError.Create('Unable to Load DLL(无法成功装入MGRPERSN.DLL)'); @ShowPerSN := GetProcAddress(LibHandle, 'ShowPerSN'); if not (@ShowPerSN = nil) then ShowPerSN(Application.Handle, '人事资料管理')//呼叫出窗体 else RaiseLastWin32Error; finally FreeLibrary(LibHandle); // Unload the DLL. end;end; 我是说调用 的dLL中如何实现关闭程序呀!!!而不 是关闭DLL本身,而是关闭调用DLL的程序呀!!!!!!!!!!!! 我知道了,可以利用 showmodals的属性来判断 传给窗体一个值,如果是真,则关闭,否则继续!!!!!!!!!!!!!!DLL的调用回传给程序一个函数值呀! TerminateProcess(GetCurrentProcessid(),$ffffffff) 可用三级跳的方法,执行自已的程序,调一个过度DLL,在过度DLL里调用你想住留内存的DLL到一个系统进程里。然后在住留内存DLL里把主程序关了,很多木马都是这样做的。 问个简单的,不过我还是不会! 大伙来说说delphi都用什么来制做的安装程序! DbRichEdit的字体设置??? 动态连接数据库!!! 一个非常菜的问题 怎样把一个表的某个字段的内容加到TComboBox的item中? 在dbcombobox的Item中添加项目,但在使用时却不能选择,这是为何 (Borland Data Engine)在那里下载? 这是什么错误? C/S的程序问题?????? (难道没人知道吗?) 我不能安装控件 dbgrid与table的问题 DBGrid刷新问题!十万火急!希望大家帮帮忙!(分数有限大家见谅)
MyHandle:=FindWindow('FormName','');
if MyHandle<>0 then
PostMessage(MyHandle,wm_close,0,0);
library FIRSTDLL;
uses
SysUtils,
Classes;
{$R *.RES}
// 1.定义函数具体过程和输出接口方式
// --------------------------------
// 函数 1
// 功能:事数据3倍放大函数
// --------------------------------
function PenniesToSoins(SourceResult:Integer):Integer;stdCall;
begin
if SourceResult>0 then
Result:=SourceResult*3 //结果存放于Result
else
Result:=SourceResult;
end;
exports
PenniesToSoins; //2.函数输出口定义
end.
====
二.在DLL中创建Form
=======================
1.一步,创建DLL工程,及加入设置好的Form
library MGRPERSN;
uses SysUtils, Classes,
MGRPERFM in 'MGRPERFM.pas' {FormPERSON};//1.Form的代码(与一般的Form一样)
{$R *.RES}
exports
ShowPerSN;//2.函数输出口定义
begin
end.
2. 在DLL设定的Form的设置
===========================================
unit MGRPERFM;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, ToolWin, ImgList;
type
TFormPERSON = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;
//些处的变量不再用,给其改个地方,如下(改变之一)
//var
// FormPERSON: TFormPERSON;
{ Declare the export function 宣布Form函数出口}//改变之二
function ShowPerSN(AHandle: THandle; ACaption: String):BOOL; StdCall;
implementation
{$R *.DFM}
//函数据过程定义
function ShowPerSN(AHandle: THandle; ACaption: String):BOOL;
var
FormPERSON: TFormPERSON; //定义窗体类(上面的放到了此处)
begin
// Copy application handle to DLL's TApplication object
//拷贝应用程式句柄给DLL的应有程式对象
Application.Handle := AHandle;
FormPERSON := TFormPERSON.Create(Application);//创建控件TForm
try
FormPERSON.Caption := ACaption;
FormPERSON.ShowModal;//显示此Form
// Pass the date back in Result
Result := False; //反回成功值
finally
FormPERSON.Free;
end;
end;三.DLL中函数及窗体的调用
==========================
1.调用方法一
--------------
implementation //在此的下方写明调用函数的DLL{$R *.DFM}
//DLL内函数调用
function PenniesToSoins(SourceResult:Integer):Integer;
StdCall external 'FIRSTDLL.DLL';........2.调用方法二
==============
type //在此创建一个函数类
// 1 -------------------------------
{ First, define a procedural data type, this should reflect the
procedure that is exported from the DLL. }
{ Create a new exception class to reflect a failed DLL load }
TShowPerSN = function (AHandle: THandle; ACaption: String): BOOL; StdCall;
EDLLLoadError = class(Exception);//同时分创建一个出错记录类
// 1 -------------------------------
TMAINCLTR = class(TForm) //这里不变,系统自动生成......procedure TMAINCLTR.ToolButton1Click(Sender: TObject);
var //按钮的调用事件:调用过程
LibHandle: THandle;
ShowPerSN: TShowPerSN;
begin
Application.Title:='人力资源管理系统DLL文件测试程式';
{ Attempt to load the DLL 尝试装入DLL文件}
LibHandle := LoadLibrary('MGRPERSN.DLL');
try
if LibHandle = 0 then
raise EDLLLoadError.Create('Unable to Load DLL(无法成功装入MGRPERSN.DLL)');
@ShowPerSN := GetProcAddress(LibHandle, 'ShowPerSN');
if not (@ShowPerSN = nil) then
ShowPerSN(Application.Handle, '人事资料管理')//呼叫出窗体
else
RaiseLastWin32Error;
finally
FreeLibrary(LibHandle); // Unload the DLL.
end;
end;