![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
urgent: kol+freelibrary - access violation [Delphi]
Riton © (2005-09-07 19:06:00)Hello,
I used the Demo "DemoVCL2KOLDLL" (kol website : downloads > demos > ModalVCL2KOLDLL) and tried to modify it so that the dll becomes dynamic.
I encountered a problem by using Freelibrary !
When I quit the application "VCLProject1.exe", the error message which occurs is :
Access Violation at the address 00AF3DD8. Read of address 00AF3DD8.
What happens ?
Here is the code with the modifications in VCLUnit.pas :
unit VCLUnit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
//procedure CallKOLFormModal; external 'KOLDll.dll' name 'CallKOLFormModal';
var
CallKOLFormModal: procedure;
dll:thandle;
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
// CallKOLFormModal;
dll:=loadlibrary('KOLDLL.dll');
CallKOLFormModal:=GetProcAddress(dll,'CallKOLFormModal');
CallKOLFormModal;
Freelibrary(dll);//if I use freelibrary, problem is "Access Violation"!
end;
end.
Thank you very much for resolving this problem.
Riton.
Riton (2005-09-09 18:34:00) [1]Alas, it doesn't work.
- On the one hand there is a type compatibility problem with the following code :
if CallKOLFormModal <> 0 then CallKOLFormModal;
- On the other hand, if I suppress this code, I find again the access violation error :
Access Violation at the address 00AF3DD8. Read of address 00AF3DD8.
Sorry that your code doesn't work.
If you want or have time to, I can send a zip file to you where the modifications are brought by me.
Riton.
Thaddy (2005-09-08 20:36:00) [2]Yes. Or an example if you don't need it after it was modal and to save resources:
procedure TForm1.Button1Click(Sender: TObject);
var dll:THandle;
begin
// CallKOLFormModal;
dll:=loadlibrary('KOLDLL.dll');
if dll <> 0 {or really >=32 i think, no win32.hlp on my GSM ;) } then
begin
CallKOLFormModal:=GetProcAddress(dll,'CallKOLFormModal');
if CallKOLFormModal <> 0 then CallKOLFormModal;
Freelibrary(dll);
end;
end;
Riton (2005-09-08 19:52:00) [3]Thanks very much for your help Wiz@rd and Thaddy.
Maybe a solution ?
The dll is unloaded when application is destroying.
There is anyway no more error with this procedure. I hope that it is a good way to solve the problem with freelibrary.
procedure TForm1.Form1Destroy(Sender: TObject);
begin
Freelibrary(dll);
end;
Thaddy (2005-09-08 16:07:00) [4]If you have the error address, why do you not use the debugger?
The example as such does not contain erronious code.
Strategy one:
Check if the library is still loaded!
Check the call stack!
Strategy two:
Steps:
1. write down error address.
2. press F7 to start debugging session (step through mode)
3. press alt+G and enter address.
Look where it jumps to.
If this doesn't work, compile in full debug mode and repeat the above.
I am afraid you will not get any serious answer here before you properly debug your code yourself.
Wiz@rd (2005-09-07 23:59:00) [5]Try use Freelibrary on program terminating