dll是最普遍的。
但也有些专用的,比如photoshop等。

解决方案 »

  1.   

    好象有interface等的,我也不太清楚
      

  2.   

    插件程序分主程序和插件程序
    主程序文件是标准的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.