Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2003.07.31;
Скачать: CL | DM;

Вниз

Работа с Dll   Найти похожие ветки 

 
Salvator ©   (2003-07-17 22:38) [0]

Мастера, подскажите. Работаю с Dll, если загружаю ее динамически, то она не работает.
Пример динамической загрузки:

var
Form1: TForm1;
Path:Function(i:integer):PChar;
LibHandle: THandle;

procedure TForm1.Button1Click(Sender: TObject);
begin
@Path := nil;
LibHandle := LoadLibrary("Functions.DLL");
if LibHandle >= 32 then
begin
@Path := GetProcAddress(LibHandle,"Path");
if @Path <> nil then
Edit3.Text:=String(Path(StrToInt(Edit1.Text)));
end;
FreeLibrary(LibHandle);
end;

А если загружаю статически:

Function Path(i:integer):PChar;stdcall;external "Functions";

то все нормально. В чем может быть проблема?


 
panov ©   (2003-07-17 22:43) [1]

var
Form1: TForm1;
Path:Function(i:integer):PChar; stdcall;
...


 
AbrosimovA ©   (2003-07-18 08:25) [2]

Всё приведенное ниже работало великолепно и возможно важно будет как пример. В DLL у меня спрятано модальное окошко "О программе", которое я вызывал нажатием на кнопку меню.

Динамический вызов DLL у себя я делал так:

unit Pro;

interface

uses .....

type TAboutD=function: boolean;

type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
N1: TMenuItem;
procedure N1Click(Sender: TObject);

private
DLLHandle: THandle;
ExternalFunctionAboutD: TAboutD;
public
end;

var
Form1: TForm1;
AboutDLL: boolean;

procedure TForm1.N1Click(Sender: TObject);
begin
DLLHandle:=LoadLibrary("DialogDLL.dll");
try
@ExternalFunctionAboutD:=GetProcAddress(DLLHandle,
PChar("AboutD"));
AboutDLL:=AboutD;
finally
FreeLibrary(DLLHandle);
end;
end;


А сама DLL выглядела следующим образом:

library DialogDLL;

uses
SysUtils,
Classes,
About in "About.pas" {AboutBox};

{$R *.res}


exports AboutD;

begin
end.

unit About;

interface

uses ......;

type
TAboutBox = class(TForm)
.
.
.

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

var
AboutBox: TAboutBox;
function AboutD: boolean;

implementation

{$R *.dfm}

function AboutD: boolean;
begin
AboutBox := TAboutBox.Create(Application);
AboutBox.ShowModal;
end;



 
KSergey ©   (2003-07-18 09:08) [3]

AbrosimovA © (18.07.03 08:25)

Вам, конечно, "повезло", однако же (как верно упомянул panov © (17.07.03 22:43)) стоит написать так, и не забывать об этом всегда:

type TAboutD=function: boolean; stdcall;

function AboutD: boolean; stdcall;



Страницы: 1 вся ветка

Текущий архив: 2003.07.31;
Скачать: CL | DM;

Наверх




Память: 0.47 MB
Время: 0.02 c
14-100952
Князь Мышкин
2003-07-15 12:25
2003.07.31
Образец настоящего программирования


3-100611
DBDev
2003-07-09 15:11
2003.07.31
Проблема с TDBImage! Подскажите ПЛИЗ!!!


14-100884
mikhasenko.anton
2003-07-16 08:25
2003.07.31
Где найти компонент DBF?


3-100596
Appa
2003-07-09 09:40
2003.07.31
IB


6-100866
dzmitry_
2003-04-20 12:57
2003.07.31
GetHideShare