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

Вниз

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

 
Unknown   (2003-11-12 12:09) [0]

Делаю обмен параметрами формы с динамической Dll; нужные значения получил и сразу же выкидуется сообщение об ошибке в приложении


 
Digitman ©   (2003-11-12 12:16) [1]

поздравляю


 
Unknown   (2003-11-12 12:19) [2]

Вот процедура чтение данных

procedure TForm1.Button3Click(Sender: TObject);
type
TLoad=procedure(var a:string;var b:integer);
var
hdll:THandle;
Load:TLoad;
s:string;
i:integer;
begin
hdll:=LoadLibrary("Boot");
@Load:=GetProcAddress(hdll,"Load");
Load(s,i);
ShowMessage(s);
ShowMessage(IntToStr(i));
FreeLibrary(hdll);
end;


 
Digitman ©   (2003-11-12 12:40) [3]

и какое же сообщение ? "выкидуется" у тебя ? гадать будем ?


 
AbrosimovA   (2003-11-12 12:51) [4]

А у тебя есть uses ShareMem?
А в процедуре LoadLibrary разве не полностью пишется Boot.dll?
А где код самой dll?
И т.д.......


 
АлексейК   (2003-11-12 13:16) [5]

String из Dll, конечно можно но аккуратно, а ошибка наверное на FreeLibrary(hdll);


 
han_malign ©   (2003-11-12 14:03) [6]

> String из Dll, конечно можно но аккуратно
- здесь явно не аккуратно, т.к. String здесь Var параметр.

Ошибка(вероятнее всего AV) происходит после ShowMessage(s); - когда менеджер памяти приложения пытается освободить локальную строку S, которая была создана в менеджере памяти DLL.

Циклограмма:
1. Автоматическая инициализация локальной переменой S=nil (compiler magic - для строк, динамических массивов и интерфейсов(аналогично для полей перечисленых типов, локальных переменных структурного типа(record)), т.к., у них задействован механизм подсчета ссылок(для автоматического управления выделением памяти))
................
2. Load(s,..) - передача @s в DLL .
DLL: 3. Выделение памяти для s (в одном аддресном пространстве, но с разными менеджерами памяти)...
4. ShowMessage(s) (s - не изменяется, реалокации памяти не происходит).
5. Освобождение локальной строки S, соданной в другом менеджере памяти - получаем AV.
ЧТД

см. AbrosimovA - "uses ShareMem"


 
Unknown   (2003-11-12 17:11) [7]

Ошибка

Project Project1.exe raised exception class EInvalidPointer with message "Invalid pointer operation".

Исходник библиотеки

library Boot;

uses
windows,
SysUtils,
Classes,
ShareMem,
Forms,
DB,
DBTables;

type
TTable1=class(TTable)
end;

var
Table:TTable1;

{$R *.res}

procedure Load(var s:string;var i:integer);
begin
i:=0;
Table:=TTable1.Create(Application);
Table.DatabaseName:=GetCurrentDir;
Table.TableName:="Data.db";
Session.AddPassword("sppasformyform");
Table.Active:=True;
Table.First;
s:=Table.FieldByName("Text").AsString;
i:=1;
Table.Next;
while not Table.Eof do
begin
s:=s+#13+Table.FieldByName("Text").AsString;
inc(i);
Table.Next;
end;
Table.Close;
end;

exports
Load;

begin
end.


 
Digitman ©   (2003-11-12 17:18) [8]

ты читал это ?

If a DLL exports routines that pass long strings or dynamic arrays as parameters or function results (whether directly or nested in records or objects), then the DLL and its client applications (or DLLs) must all use the ShareMem unit. The same is true if one application or DLL allocates memory with New or GetMem which is deallocated by a call to Dispose or FreeMem in another module. ShareMem should always be the first unit listed in any program or library uses clause where it occurs.

ShareMem is the interface unit for the BORLANDMM.DLL memory manager, which allows modules to share dynamically allocated memory. BORLANDMM.DLL must be deployed with applications and DLLs that use ShareMem. When an application or DLL uses ShareMem, its memory manager is replaced by the memory manager in BORLANDMM.DLL.


 
han_malign ©   (2003-11-12 17:50) [9]

> Digitman © (12.11.03 17:18) [8]
- эт еще не все:

If a DLL exports routines that pass long strings or dynamic arrays as parameters or function results (whether directly or nested in records or objects), then the DLL and its client applications (or DLLs) must all use the ShareMem unit. The same is true if one application or DLL allocates memory with New or GetMem which is deallocated by a call to Dispose or FreeMem in another module. ShareMem should always be the first unit listed in any program or library uses clause where it occurs.

ShareMem is the interface unit for the BORLANDMM.DLL memory manager, which allows modules to share dynamically allocated memory. BORLANDMM.DLL must be deployed with applications and DLLs that use ShareMem. When an application or DLL uses ShareMem, its memory manager is replaced by the memory manager in BORLANDMM.DLL.


 
Digitman ©   (2003-11-12 17:54) [10]


> han_malign


ну это да, это как бы подразумевалось , что автор учел ...
хотя ... шут его знает)...



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

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

Наверх




Память: 0.49 MB
Время: 0.024 c
7-79210
NaemNIK
2003-09-15 13:38
2003.11.24
Ctrl-Alt-Dl


1-78978
velial
2003-11-14 14:40
2003.11.24
MDI одна форма


14-79183
aVast
2003-10-27 16:50
2003.11.24
Замечательнейшая вещь EhLib!!!


3-78786
kasa
2003-11-05 18:42
2003.11.24
Insert


11-78872
microlab
2003-03-09 21:45
2003.11.24
Каталог программ