dll是最普遍的。
但也有些专用的,比如photoshop等。
但也有些专用的,比如photoshop等。
解决方案 »
- 提取memo每行数字,计算每行数字累加之和问题
- fastReport 主项 细项 的 设置问题 ???
- ADOQuery的数据从链接服务器上取过来的,更新时提示缺少用于更新或刷新的基本表信息
- bde连接数据库时的问题
- 请问串口通信中,10进制的19和17收不到,怎么办?
- 我是个新手,问个问题,很简单!
- 有没有制作DELPHI系统托盘程序的源码范例?
- 有什么好软件可以制作演示系统
- mysql数据库存放路径
- 怎么能把自己定义的*.Pas文件加入到Delphi的New Items中,以便以后能够直接选择它建立一个新的应用。
- 请有WinNT系统的朋友帮忙,我想知道一个窗体的长和宽?
- 一个多线程的处理问题,同时也是一个涵数调用问题,请高手们帮帮忙:) 谢谢我
主程序文件是标准的exe文件,但是程序能查找指定目录下的插件(dll),并且动态加载
而且,主程序调用插件的接口是定义好的,再开发插件是在指定接口下开发的
插件就是dll文件,但是必须提供主程序调用插件的接口,要不然主程序是不能调用插件的
用插件程序的好处就是可以方便的增加程序的功能
最著名、最成功的插件程序应该是photoshop,winamp了!给你一个例子:
主程序:unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
TPluginDescribe = Function:Boolean; stdcall;
TPluginDrawDescribe = procedure(DC:HDC;Rect:TRect); stdcall;
TPlugindia = procedure(); stdcall;
TForm1 = class(TForm)
ListBox1: TListBox;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure ListBox1DblClick(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button1Click(Sender: TObject);
private
LibHandle: HMODULE;
DwarProc: TPluginDrawDescribe;
dia: TPlugindia ;
procedure LoadPlugins;
procedure LoadPlugin(sr: TSearchRec);
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.FormCreate(Sender: TObject);
begin
LibHandle:=0;
LoadPlugins;
end;procedure TForm1.LoadPlugins;
var
sr: TSearchRec;
path: string;
Found: Integer;
begin
path := ExtractFilePath(Application.Exename);
try
Found := FindFirst(path + '*.DLL', 0, sr);
while Found = 0 do
begin
LoadPlugin(sr);
Found := FindNext(sr);
end;
finally
FindClose(sr);
end;
end;procedure TForm1.LoadPlugin(sr: TSearchRec);
var
iLibHandle: HMODULE;
pDescribeProc: TPluginDescribe;
pDwarProc: TPluginDrawDescribe;
begin
iLibHandle := LoadLibrary(Pchar(sr.Name));
if iLibHandle <> 0 then
begin
try
pDescribeProc := GetProcAddress(iLibHandle, 'loadpicture');
pDwarProc := GetProcAddress(iLibHandle, 'drawpicture');
if Assigned(pDescribeProc) and Assigned(pDwarProc) then
ListBox1.Items.Add(sr.Name);
finally
FreeLibrary(iLibHandle);
end;
end else
ShowMessage('loading Dll file error!');
end;procedure TForm1.ListBox1DblClick(Sender: TObject);
var pDescribeProc: TPluginDescribe;
begin
if ListBox1.ItemIndex<>-1 then
begin
if LibHandle<>0 then
FreeLibrary(LibHandle);
DwarProc:=nil;
LibHandle := LoadLibrary(PChar(ListBox1.Items[ListBox1.ItemIndex]));
if LibHandle <> 0 then
begin
try
pDescribeProc := GetProcAddress(LibHandle, 'loadpicture');
if pDescribeProc then
begin
DwarProc := GetProcAddress(LibHandle, 'drawpicture');
dia:= GetProcAddress(LibHandle, 'dilog');
Invalidate;
end;
Except
FreeLibrary(LibHandle);
LibHandle:=0;
end;
end
else
ShowMessage('loading Dll file error!');
end;
end;procedure TForm1.FormPaint(Sender: TObject);
begin
try
if (LibHandle<>0) and Assigned(DwarProc) then
DwarProc(Self.Canvas.Handle,Self.ClientRect);
Except
if LibHandle<>0 then
begin
FreeLibrary(LibHandle);
LibHandle:=0;
end;
end;
end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if LibHandle<>0 then
begin
FreeLibrary(LibHandle);
LibHandle:=0;
end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
if (LibHandle<>0) and Assigned(Dia) then
dia;
end;end.插件dll:unit PlugInUnit; interface
Uses Graphics,extdlgs,Windows;Function loadpicture:Boolean;
procedure drawpicture(DC:HDC;Rect:TRect);export; stdcall;Var Picture:TPicture;implementationprocedure drawpicture(DC:HDC;Rect:TRect);
Var cCanvas:TCanvas;
i,j:Integer;
begin
if (Picture<>nil) and not Picture.Graphic.Empty then
begin
cCanvas:=TCanvas.Create;
try
cCanvas.Handle:=DC;
cCanvas.FillRect(Rect);
i:=0;
While i<(Rect.Right-Rect.Left)+Picture.Width do
begin
j:=0;
While j<(Rect.Bottom-Rect.Top)+Picture.Height do
begin
cCanvas.Draw(i,j,Picture.Graphic);
Inc(j,Picture.Height);
end;
Inc(i,Picture.Width);
end;
finally
cCanvas.Free;
end;
end;
end;Function loadpicture:Boolean;
begin
Result:=False;
Picture:=TPicture.Create;
with TopenpictureDialog.Create(nil) do
begin
try
if Execute then
begin
Picture.LoadFromFile(FileName);
Result:=True;
end;
finally
Free;
end;
end;
end;end.