![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
Подскажите пример исходника программы работающей с dll ?
Not © (2006-09-13 04:21:00)Нужно, чтобы программа могла работать с dllками.
Программа вызывает dll - Dll - может вызывать некие нужные ей функции программы - и под конец возвращает результат своей работы.
Как такое можно организовать ?
Если можно, дайте исходники примеров такой программы и Dll ?
Zeqfreed (2006-09-15 01:17:00) [21]Перед передачей данных типа String между приложением и библиотекой следует очень внимательно прочитать комментарий, обозначенный в шаблоне библиотеки, генерируемом средой.
Not (2006-09-15 01:14:00) [22]Джо
Спасибо.
> Elen © (14.09.06 08:10) [5]
> > Мне надо передать в DLL следующие данные:
>
> ИМХО лучше указателем.
А как именно ? Можно пример ?
Elen (2006-09-14 08:10:00) [23]
> Мне надо передать в DLL следующие данные:
ИМХО лучше указателем.
Джо (2006-09-14 03:34:00) [24]> [2] Not (14.09.06 03:22)
> А как загрузить динамически? Делаю так:
Делай так:
var
GetInfo1 : function : TRegi; stdcall;
Not (2006-09-14 03:27:00) [25]И ещё вопрос.
Мне надо передать в DLL следующие данные:
type
TVector3f = array [0..2] of Single;
TFGTData = record
PTInd : array [0..2] of Integer;
TXInd : array [0..2] of Integer;
Enable : Boolean;
NRData : Integer;
end;
TFData = record
FGTData : array of TFGTData;
Name : string;
MName : string;
Visible : Boolean;
NTData : Byte;
end;
TFDatas = array of TFData;
TTXData = record
X, Y : Single;
Enabled : Boolean;
end;
TPData = record
ITData : TVector3f;
Enabled : Boolean;
BNData : SmallInt;
end;
TMData = record
Name : string;
PData : array of TPData;
TXData : array of TTXData;
FData : TFDatas;
Visible : Boolean;
end;
TMDatas = array of TMData;
var
MDatas1 : TMDatas;
Передать нужно MDatas1, чтобы в DLL их можно было редактировать. Как такое лучше организовать ?
Тут dll - это типа плагин, который может таким образом изменять данные программы.
Not (2006-09-14 03:22:00) [26]2 Elen.
Спасибо за пример !
А как загрузить динамически? Делаю так:
type
TRegi = record
InterfaceType : Integer;
Version : Integer;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
InfoA2 : TRegi;
GetInfo1 : function : TRegi;
LibHandle : THandle;
begin
@GetInfo1 := nil;
LibHandle := LoadLibrary('Test1.dll');
if LibHandle >= 32 then begin
@GetInfo1 := GetProcAddress(LibHandle, 'GetInfo1');
if @GetInfo1 <> nil then begin
InfoA2 := GetInfo1;
s1 := IntToStr(InfoA2.Version);
ShowMessage(s1);
end;
end;
FreeLibrary(LibHandle);
end;
Но вместо числа 1 в Version я получаю билиберду. В чём тут ошибка ?
Функция в Dll выглядит так :
function GetInfo1: TRegi; stdcall;
begin
Result.InterfaceType := 1;
Result.Version := 1;
beep;
end;
Объявляю её так :
exports
GetInfo1;
Elen (2006-09-13 08:19:00) [27]Привет Not
Вот те ДЛЛка
library Project2;
{ 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
SysUtils,
Classes;
{$R *.res}
//********** FUNCTION **********
function BlaBla(s:integer):integer;
begin
result:=s+s;
end;
//********** END FUNCTION ******
exports BlaBla;
begin
end.
А вот работа с ней (статик вызов)
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
function BlaBla(s:integer):integer; external 'project2.dll';
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
caption:=inttostr(blabla(5));
end;
end.
И Иди рулить мануалы по DLL