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

Вниз

При закрытии возникает ошибка   Найти похожие ветки 

 
SerGH ©   (2006-05-10 22:34) [0]

Здравствуйте,Уважаемые Мастера. Цель такая:вывод метки из Dll-ки.
Код проги:
unit Unit1;

interface

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

type
 TForm1 = class(TForm)
   Button1: TButton;
   Label1: TLabel;
   procedure Button1Click(Sender: TObject);
 private
   { Private declarations }
 public
   { Public declarations }
 end;

var
 Form1: TForm1;
implementation
Function TestDLL:PChar; Stdcall; External "Test.dll";
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
Label1.Caption:=TestDLL();
end;

end.

сама Dll:
library Test;

{ 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
 ShareMem,
 SysUtils,
 Windows,
 Dialogs,
 Unit1 in "Unit1.pas" {Form1};

{$R *.res}
function TestDLL(): PChar; Stdcall;

begin
Result:=PChar("222");
end;

Exports TestDLL;

begin
end.

Все,вроде, выполняется, но возникает оши бка при закрыти формы:
Project project1.exe raised class EInvalidPointer with message ‘invalid pointer operation’. Process stopped. Use Step or Run to continue.
Error: runtime error 217 at 00413754
Не могли бы Вы подсказать, как решить эту проблему.
Заранее Всем Благодарен


 
sniknik ©   (2006-05-11 00:07) [1]

первое ShareMem в модуле бесполезен, т.к. уже не первый... надо ставить обязательно в файле проекта (*.dpr), в dll обьявлено правильно.

второе, особого смысла в PChar; и Stdcall; нет, раз уж ShareMem стоит, то можно пользоваться строками, проще (совместимостью с С все одно и не пахнет), а раз так то и вызов обьявлять сишный тоже не надо.    

т.е. с учетом этого пишем в dll просто
function TestDLL(): string;
begin
 Result:= "222";
end;

ну и правим обьявление в проекте, + ставим на место ShareMem. должно работать.


 
Leonid Troyanovsky ©   (2006-05-11 00:55) [2]


> sniknik ©   (11.05.06 00:07) [1]

> второе, особого смысла в PChar;


и третье: особого смысла в dll тоже нет.
Ну, или уж, на худой конец, LoadString.

--
Regards, LVT.



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

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

Наверх




Память: 0.47 MB
Время: 0.04 c
15-1146561750
ANB
2006-05-02 13:22
2006.05.28
Телефон Вилючинского городского суда


8-1135176215
Woolen
2005-12-21 17:43
2006.05.28
Формат bitmap


1-1145271748
Viper_Omsk
2006-04-17 15:02
2006.05.28
Как передать данные из Excel в StringGrid?


2-1146962389
Интересующийся
2006-05-07 04:39
2006.05.28
Проект Delphi без System, как?


2-1147380746
EZHIK
2006-05-12 00:52
2006.05.28
Кнопки назад и вперед и вернуться.