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

Вниз

Форма в DLL... В чем ошибка???   Найти похожие ветки 

 
Sirus   (2002-04-03 15:30) [0]

Привет ВСЕМ кто читает!!!
Создал форму в DLL... пытаюсь вызвать ее из программы...
загружаю DLL вызываю процедуру, которая показывает мне форму... все работает...
А вот когда закрываю форму выскакивает ошибка Access violation...
Подскажите как лечить...


 
Suntechnic   (2002-04-03 16:37) [1]

Код в студию. Особенно интересуют места, где форма создаётся и где именно удаляется.


 
Sirus   (2002-04-04 06:20) [2]

Вот код DLL проекта...

library proba;

uses
Windows,
SysUtils,
forms,
Classes,
main in "main.pas" {AForm};

function MainFormShowModal(Capt:string):integer; stdcall;
Begin
AForm:=TAForm.Create(Application);
Result:=AForm.ShowModal;
AForm.Free;
End;

{$R *.RES}

exports MainFormShowModal;

begin
end.


А это код формы в DLL

unit main;

interface

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

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

var
AForm: TAForm;

implementation

{$R *.DFM}

procedure TAForm.Button1Click(Sender: TObject);
begin
ShowMessage("Hello! This is a DLL form and message");
end;

end.


Исходник проекта вызывающего форму...

unit dmunit;

interface

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

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

var
Form1: TForm1;
MainFormShowModal:procedure(Capt:String);
LibHandle: THandle;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
@MainFormShowModal := nil;
LibHandle := LoadLibrary("proba.dll");
if LibHandle >= 32 then begin
@MainFormShowModal := GetProcAddress(LibHandle,"MainFormShowModal");
if @mainFormShowModal <> nil then
MainFormShowModal("Hello");
end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
FreeLibrary(LibHandle);
end;

end.


Прошу... Посоветуйте что можете... Седня я должен добить эту проблему...


 
Suntechnic   (2002-04-04 07:07) [3]

Ты читал, что Delphi для тебя пишет, когда ты dll создаёшь?

{ 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. }


Приведи свой код в соответствие, а там дальше видно будет, всё остальное вроде в порядке на первый взгляд.



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

Форум: "WinAPI";
Текущий архив: 2002.06.06;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.45 MB
Время: 0.007 c
7-18174
Aric
2002-03-10 14:20
2002.06.06
Буфер com-порта


4-18198
heruvim4ik
2002-04-03 20:25
2002.06.06
Работа с другими приложениями


1-17879
dim-
2002-05-26 12:17
2002.06.06
интеграция в эксплорер


3-17799
Garry
2002-05-16 10:48
2002.06.06
Как получить файл EXСEL


4-18177
Керик
2002-03-31 07:48
2002.06.06
Перехват сообщения приложению





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
Английский Французский Немецкий Итальянский Португальский Русский Испанский