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

Вниз

Проблема с отображением форм из DLL   Найти похожие ветки 

 
Чайник ©   (2005-09-21 22:14) [0]

Разбираюсь с примером,  взятом из диска к книге Тейксейры  (глава 6) : отображение модальных форм из DLL. Не менял в примере ни слова. При выходе из формы вылетает Access violetion: read of adress 0x0000. Методом тыка обнаружил, что вылетает на строчке

FreeLibrary(LibHandle); // Unload the DLL.

Кто-нить может объяснить, в чем дело?


{ Copyright © 2001 Delphi 6 Developer"s Guide Xavier Pacheco
 and Steve Teixeira }

unit MainFfm;

interface

uses
 SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
 Forms, Dialogs, StdCtrls;

type
 { First, define a procedural data type, this should reflect the
   procedure that is exported from the DLL. }
 TShowCalendar = function (AHandle: THandle; ACaption: String): TDateTime; StdCall;

 { Create a new exception class to reflect a failed DLL load }
 EDLLLoadError = class(Exception);

 TMainForm = class(TForm)
   lblDate: TLabel;
   btnGetCalendar: TButton;
   procedure btnGetCalendarClick(Sender: TObject);
 end;

var
 MainForm: TMainForm;

implementation

{$R *.DFM}

procedure TMainForm.btnGetCalendarClick(Sender: TObject);
var
 LibHandle   : THandle;
 ShowCalendar: TShowCalendar;
begin

 { Attempt to load the DLL }
 LibHandle := LoadLibrary("CALENDARLIB.DLL");
 try
   { If the load failed, LibHandle will be zero.
     If this occurs, raise an exception. }
   if LibHandle = 0 then
     raise EDLLLoadError.Create("Unable to Load DLL");
   { If the code makes it here, the DLL loaded successfully, now obtain
     the link to the DLL"s exported function so that it can be called. }
   @ShowCalendar := GetProcAddress(LibHandle, "ShowCalendar");
   { If the function is imported successfully, then set lblDate.Caption to reflect
     the returned date from the function. Otherwise, show the return raise
     an exception. }
   if not (@ShowCalendar = nil) then
     lblDate.Caption := DateToStr(ShowCalendar(Application.Handle, Caption))
   else
     RaiseLastWin32Error;                                                              
 finally
   FreeLibrary(LibHandle); // Unload the DLL.
 end;
end;

end.


 
Desdechado ©   (2005-09-21 22:49) [1]

DLL твоя не загрузилась, указатель = 0
поднятие Exception заворачивает в Finally, где и гневно матюгается


 
Lamer@fools.ua ©   (2005-09-21 22:55) [2]

>>Чайник ©   (21.09.05 22:14)

Код библиотеки?


 
Чайник ©   (2005-09-22 01:04) [3]

Desdechado ©   (21.09.05 22:49) [1]
DLL твоя не загрузилась, указатель = 0
поднятие Exception заворачивает в Finally, где и гневно матюгается

<Цитата>
DLL загрузилась и прекрасно свое отработала, указатель <> 0. Гневно матюгается уже при ее выгрузке.

>Lamer@fools.ua ©   (21.09.05 22:55) [2]


{ Copyright © 2001 Delphi 6 Developer"s Guide Xavier Pacheco
 and Steve Teixeira }

library CalendarLib;

uses
 ShareMem,
 SysUtils,
 Classes,
 DLLFrm in "DLLFrm.pas" {DLLForm};

exports
 ShowCalendar;
 
begin
end.

{ Copyright © 2001 Delphi 6 Developer"s Guide Xavier Pacheco
 and Steve Teixeira }

unit DLLFrm;

interface

uses
 SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
 Forms, Dialogs, Grids, Calendar;

type

 TDLLForm = class(TForm)
   calDllCalendar: TCalendar;
   procedure calDllCalendarDblClick(Sender: TObject);
 end;

{ Declare the export function }
function ShowCalendar(AHandle: THandle; ACaption: String): TDateTime; StdCall;

implementation
{$R *.DFM}

function ShowCalendar(AHandle: THandle; ACaption: String): TDateTime;
var
 DLLForm: TDllForm;
begin
 // Copy application handle to DLL"s TApplication object
 Application.Handle := AHandle;
 DLLForm := TDLLForm.Create(Application);
 try
   DLLForm.Caption := ACaption;
   DLLForm.ShowModal;
   Result := DLLForm.calDLLCalendar.CalendarDate; // Pass the date back in Result
 finally
   DLLForm.Free;
 end;
end;

procedure TDLLForm.calDllCalendarDblClick(Sender: TObject);
begin
 Close;
end;

end.



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

Форум: "Основная";
Текущий архив: 2005.10.16;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.46 MB
Время: 0.059 c
14-1127769010
TButton
2005-09-27 01:10
2005.10.16
Драйвер модема для Siemens M65


4-1124123194
dddim
2005-08-15 20:26
2005.10.16
установить Привелегию процессу


3-1125374795
novikova
2005-08-30 08:06
2005.10.16
ado в локальной сети


5-1102660811
Denis_Ac
2004-12-10 09:40
2005.10.16
Изменение размеров потомка TCustomGroupBox


3-1125469474
Nickolay
2005-08-31 10:24
2005.10.16
Запись/чтение массива в/из поле базы данных xml





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