Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Начинающим";
Текущий архив: 2006.05.28;
Скачать: [xml.tar.bz2];

Вниз

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

 
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;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.45 MB
Время: 0.011 c
3-1144065445
beglec
2006-04-03 15:57
2006.05.28
ComboBox и Базы данных


2-1146969649
TBAPb
2006-05-07 06:40
2006.05.28
Помогите сделать поект


9-1130842218
zx
2005-11-01 13:50
2006.05.28
Microsoft посадит OpenGL под замок?


15-1146407457
Piter
2006-04-30 18:30
2006.05.28
Кто на чем смотрит DVD?


15-1146597572
kilonet
2006-05-02 23:19
2006.05.28
Перевод книги в электронный формат





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский