^_^
Dll中的窗体,显示在调用窗体的某个区域? 如调用Dll中的Form1,并放置panle1中.//可以通过修改以下代码来说明//==================================================================DLLForm.dpr
library DLLForm;{ 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
Windows,
SysUtils,
Classes,
Forms,
dialogs,
Messages,
Help in '..\新建文件夹\Help.pas' {FrmHelp};var
DLLAPP: TApplication;
DLLScreen: TScreen;
TheForm: TForm;
TheClass: TPersistentClass;{$R *.res}procedure RunDLL(DLLName, FormName, FormCaption: String; APP: TApplication; SC: TScreen) stdcall;
begin
Application := App;
Screen := SC;
RegisterClasses([TFrmHelp]);
TheClass := GetClass(PChar('T' + FormName)); if (TheClass <> nil) and TheClass.InheritsFrom(TForm) then
begin
TheForm := TForm(TheClass.Create).Create(nil);
TheForm.Show;
end;
end;procedure DLLUnLoadProc(Reason: Integer);
begin
if Reason = DLL_PROCESS_DETACH then
begin
Application := DLLApp;
Screen := DLLScreen;
SendMessage(Application.Handle, WM_CLOSE, 0, 0);
FreeLibrary(Application.Handle);
end;
end;exports
RunDLL;begin
DLLAPP := Application;
DLLScreen := Screen;
DLLProc := @DLLUnLoadProc;
end.
//==================================================================Help.pas
unit Help;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;type
TFrmHelp = class(TForm)
Button1: TButton;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;var
FrmHelp: TFrmHelp;implementation{$R *.dfm}procedure TFrmHelp.FormClose(Sender: TObject; var Action: TCloseAction);
begin
action := caFree
end;end.
//==================================================================调用窗体 Unit1.pas
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, ExtCtrls;type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
dll1: TMenuItem;
dll2: TMenuItem;
Panel1: TPanel;
procedure dll2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
Type
TRunDLL = procedure(DLLName, FormName,FormCaption: String; Application: TApplication; Screen: TScreen); stdcall;procedure RunDLLForm(DLLName, FormName,FormCaption: String; App: TApplication; SC: TScreen); stdcall;var
GetDLLHWND: HWND;
Form1: TForm1;implementation{$R *.dfm}procedure RunDLLForm(DLLName, FormName,FormCaption: String; App: TApplication; SC: TScreen); stdcall;
var
RunDLL: TRunDLL;
begin
GetDLLHWND := LoadLibrary(PChar(DLLName));
if GetDLLHWND < 32 then
begin
MessageBox(0, PChar('未找到DLL'), PChar('加载DLL失败'), MB_OK);
Exit;
end;
@RunDLL := GetProcAddress(GetDLLHWND, PChar('RunDLL'));
if @RunDLL <> nil then
begin
Try
RunDLL(PChar(UpperCase(Trim(DLLName))), PChar(UpperCase(Trim(FormName))),PChar(FormCaption), APP, SC);
Except
Raise Exception.Create('T' + FormName + '不存在');
End;
end;
end;procedure TForm1.DLL2Click(Sender: TObject);
begin
RunDLLForm('DLLForm', 'FrmHelp', 'FrmHelp', Application, Screen);
end;end.
Dll中的窗体,显示在调用窗体的某个区域? 如调用Dll中的Form1,并放置panle1中.//可以通过修改以下代码来说明//==================================================================DLLForm.dpr
library DLLForm;{ 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
Windows,
SysUtils,
Classes,
Forms,
dialogs,
Messages,
Help in '..\新建文件夹\Help.pas' {FrmHelp};var
DLLAPP: TApplication;
DLLScreen: TScreen;
TheForm: TForm;
TheClass: TPersistentClass;{$R *.res}procedure RunDLL(DLLName, FormName, FormCaption: String; APP: TApplication; SC: TScreen) stdcall;
begin
Application := App;
Screen := SC;
RegisterClasses([TFrmHelp]);
TheClass := GetClass(PChar('T' + FormName)); if (TheClass <> nil) and TheClass.InheritsFrom(TForm) then
begin
TheForm := TForm(TheClass.Create).Create(nil);
TheForm.Show;
end;
end;procedure DLLUnLoadProc(Reason: Integer);
begin
if Reason = DLL_PROCESS_DETACH then
begin
Application := DLLApp;
Screen := DLLScreen;
SendMessage(Application.Handle, WM_CLOSE, 0, 0);
FreeLibrary(Application.Handle);
end;
end;exports
RunDLL;begin
DLLAPP := Application;
DLLScreen := Screen;
DLLProc := @DLLUnLoadProc;
end.
//==================================================================Help.pas
unit Help;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;type
TFrmHelp = class(TForm)
Button1: TButton;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;var
FrmHelp: TFrmHelp;implementation{$R *.dfm}procedure TFrmHelp.FormClose(Sender: TObject; var Action: TCloseAction);
begin
action := caFree
end;end.
//==================================================================调用窗体 Unit1.pas
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, ExtCtrls;type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
dll1: TMenuItem;
dll2: TMenuItem;
Panel1: TPanel;
procedure dll2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
Type
TRunDLL = procedure(DLLName, FormName,FormCaption: String; Application: TApplication; Screen: TScreen); stdcall;procedure RunDLLForm(DLLName, FormName,FormCaption: String; App: TApplication; SC: TScreen); stdcall;var
GetDLLHWND: HWND;
Form1: TForm1;implementation{$R *.dfm}procedure RunDLLForm(DLLName, FormName,FormCaption: String; App: TApplication; SC: TScreen); stdcall;
var
RunDLL: TRunDLL;
begin
GetDLLHWND := LoadLibrary(PChar(DLLName));
if GetDLLHWND < 32 then
begin
MessageBox(0, PChar('未找到DLL'), PChar('加载DLL失败'), MB_OK);
Exit;
end;
@RunDLL := GetProcAddress(GetDLLHWND, PChar('RunDLL'));
if @RunDLL <> nil then
begin
Try
RunDLL(PChar(UpperCase(Trim(DLLName))), PChar(UpperCase(Trim(FormName))),PChar(FormCaption), APP, SC);
Except
Raise Exception.Create('T' + FormName + '不存在');
End;
end;
end;procedure TForm1.DLL2Click(Sender: TObject);
begin
RunDLLForm('DLLForm', 'FrmHelp', 'FrmHelp', Application, Screen);
end;end.
解决方案 »
- 不惜 重分 高分 解决一个关于存储过程的问题.高手请进帮忙解决,非高手请进学习!!谢谢!!
- 如何在编程实现在播放视频文件时候截图(麻烦举个例子)
- 请有从access库导入sqlserver的源代吗
- 西安的DELPHI!!!
- 问题求解!
- 菜鸟提问:请高手赐教,如何实现在一个Edit框中输入值关掉该应用程序以后,使下次开启时记住该值,不用再输一遍!
- 请问哪里有做报表的第三方控件下载?
- 高程考什么语言? C/C++ 么?还有汇编?另外还需要一些什么参考书呢?
- 如何将子窗体彻底关闭
- 高分求救!!!请问怎样获得TAdoQuery 的表名。。。急。。。高手讲请
- oracle: 用ADOQUERY执行带日期类型的INSERT 语句出错
- 字体设成什么好?
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 ShareMem;
在dll中最好不要使用string类型,最好使用pchar
ShareMem,//放到最上边
Windows,
SysUtils,
Classes,
Forms,
dialogs,
Messages,
Help in '..\新建文件夹\Help.pas' {FrmHelp};
能说的详细一些吗
+ ShareMem之后,其他内容如何调整才能得到我想要的结果?
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
FSwifte in 'FSwifte.pas',
SysUtils,
Classes,
Forms,
FHelp in 'FHelp.pas' {frmHelp};{$R *.res}function GetDllForm(AApplication: TApplication; AFormClass: PChar;
AFormName: PChar): THandle; stdcall;
var
oForm: TForm;
begin
Result := 0;
Application := AApplication;
oForm := TForm(TComponentClass(FindClass(AFormClass)).Create(Application.MainForm));
if oForm <> nil then
begin
oForm.Name := AFormName;
Result := Integer(oForm);
end;
end;exports
GetDllForm;begin
end.unit FHelp;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;type
TfrmHelp = class(TForm)
pnlMain: TPanel;
Button1: TButton;
private
{ Private declarations }
public
{ Public declarations }
end;var
frmHelp: TfrmHelp;implementation{$R *.dfm}initialization
RegisterClass(TfrmHelp);finalization
UnregisterClass(TfrmHelp);end.unit FSwifte;interfaceimplementationinitialization
IsLibrary := False;end.
program ExeForm;uses
Forms,
FMain in 'FMain.pas' {Form1};{$R *.res}begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.unit FMain;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;type
TCallDllForm = function (AApplication: TApplication; AFormClass: PChar;
AFormName: PChar): THandle; stdcall;type
TForm1 = class(TForm)
pnlMain: TPanel;
Load: TButton;
procedure LoadClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
FDllHandle: THandle;implementation{$R *.dfm}procedure TForm1.LoadClick(Sender: TObject);
var
oCall: TCallDllForm;
hFormHandle: THandle;
oForm: TForm;
oPanel: TPanel;
begin
FDllHandle := LoadLibrary('DllForm.dll');
if FDllHandle < 32 then
begin
MessageBox(0, PChar('未找到DLL'), PChar('加载DLL失败'), MB_OK);
Exit;
end;
@oCall := GetProcAddress(FDllHandle, PChar('GetDllForm'));
if @oCall <> nil then
begin
hFormHandle := oCall(Application, 'TfrmHelp', 'frmHelp');
if hFormHandle > 0 then
begin
oForm := TForm(hFormHandle);
if oForm <> nil then
begin
oForm.Align := alClient;
oForm.BorderStyle := bsNone;
Windows.SetParent(oForm.Handle, pnlMain.Handle);
oForm.Visible := True;
SetForegroundWindow(Handle);
end;
end;
end;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
FDllHandle := 0;
end;procedure TForm1.FormDestroy(Sender: TObject);
begin
if FDllHandle > 0 then
FreeLibrary(FDllHandle);
end;end.
http://blog.csdn.net/mr_liyouliang/
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
ShareMem,
Windows,
SysUtils,
Classes,
Forms,
dialogs,
Messages,
Controls,
Help in '..\新建文件夹\Help.pas' {FrmHelp};var
DLLAPP: TApplication;
DLLScreen: TScreen;
TheForm: TForm;
TheClass: TPersistentClass;
iApp: TApplication;
{$R *.res}
procedure DLLUnLoadProc(Reason: Integer);
begin
if Reason = DLL_PROCESS_DETACH then
begin
Application := DLLApp;
Screen := DLLScreen;
SendMessage(Application.Handle, WM_CLOSE, 0, 0);
FreeLibrary(Application.Handle);
end;
end;procedure RunDLL(DLLName, FormName, FormCaption: String; APP: TApplication; SC: TScreen; Parent: TCustomControl) stdcall;
begin
Application := App;
Screen := SC;
RegisterClasses([TFrmHelp]);
TheClass := GetClass(PChar('T' + FormName));
iApp := APP;
if (TheClass <> nil) and TheClass.InheritsFrom(TForm) then
begin
if not Assigned(TheForm) then
begin
TheForm := TForm(TheClass.Create).Create(nil);
windows.SetParent(TheForm.Handle,parent.Handle); //!!!!
TheForm.WindowState := wsMaximized;
end;
TheForm.Show;
end;
end;exports
RunDLL,DLLUnLoadProc;begin
DLLAPP := Application;
DLLScreen := Screen;
DLLProc := @DLLUnLoadProc;
end.