Показать сообщение отдельно
  #19  
Старый 25.09.2008, 14:30
dmdx dmdx вне форума
Начинающий
 
Регистрация: 24.05.2008
Адрес: Москва
Сообщения: 133
Репутация: 15
По умолчанию

Цитата:
Сообщение от жекаизжека
можно пример выноса в длл..если можно подробно

на форуме куча материала по поводу использования динамических библиотек. одну или две я сам поднимал поищи.

вот пример
dll
Код:
library FunDll;


uses
  SysUtils,
  dialogs,
  Classes;

{$R *.res}

procedure ShowMsg(text: pchar); stdcall; export;
begin
 ShowMessage(text);
end;

function Summ(x: integer; y: integer):integer; stdcall; export;
begin
 result:=x+y;
end;


exports
ShowMsg name 'ShowMsg',
Summ name 'Summ';

begin
end.
 

project code
Код:
unit uProgMain;

interface

uses
  Windows, Messages, SysUtils,  Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TSumm = function (x: integer; y: integer ): integer; stdcall;
  TShowMgs = procedure (text: pchar); stdcall;
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
const
 s: string = 'Welcome';
var
 dllHandle:  THandle;
 ShowMsg: TShowMgs;
begin
 @ShowMsg:=nil;
 dllHandle:=LoadLibrary(pchar('FunDll.dll'));
 if dllHandle=0 then
  exit;
 @ShowMsg:=GetProcAddress(dllHandle,'ShowMsg');
 if @ShowMsg = nil then
  exit;
 ShowMsg(pchar(s));
 @ShowMsg:=nil;
 FreeLibrary(dllHandle);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
 dllHandle: THandle;
 Suma: TSumm;
begin
 @Suma:=nil;
 dllHandle:=LoadLibrary(pchar('FunDll.dll'));
 if dllHandle<32 then
  exit;
 @Suma:=GetProcAddress(dllHandle,PChar('Summ'));
 if @Suma=nil then
  exit;
 ShowMessage(inttostr(Suma(2,5)));
 @Suma:=nil;
 FreeLibrary(dllHandle);
end;

end.
__________________
Програмист приходит на стрельбище. Стреляет. Прапор смотрит на мешень и говорит
Прапор: вы не попали ни один раз.
Программист: Пули вылетели, проблемы у вас.
Ответить с цитированием