Solved

Exit procedure in DLL

Posted on 1997-06-23
5
605 Views
Last Modified: 2010-04-04
Hi,
 
I have a program (Delphi 1) with a static DLL. I have in the DLL some units. One unit needs the DB unit.
I have the next problem: I have under NT and Win 3.1 a GPF after the second start or exit of the program. Win 95 is working.
The DLL not executes (NT & W3.1) the Exit procedures from the owned units. (The DoneSession procedure in DB is not called)
What can I do? How can I *generally* activate by the last program exit the exit procedures from the DLL owned units?

Have you any idea?  
Many thanks
0
Comment
Question by:nnn062397
  • 3
  • 2
5 Comments
 
LVL 1

Accepted Solution

by:
Gabor earned 100 total points
ID: 1337593
I not understand your answer clear, so i will answer for two question.1. How can I write the Exit procedure in a DLL?-----------------------------------------------library MyDLL;...type  TProcedure = procedure;var  PrevExitProc: TProcedure;procedure MyExitProc; far;begin  ...  if Assigned(PrevExitProc) then PrevExitProc;end;...{Library initialization}begin  PrevExitProc:=ExitProc;  ExitProc:=@MyExitProc;  ...end.2. How can I close a DLL?-------------------------This procedure will kill the dll.procedure CloseDLL(dllname: String);var  h: THandle;  puff: array[0..100] of Char;begin  StrPCopy(puff,dllname);  repeat    h:=GetModuleHandle(puff);    FreeLibrary(h);  until h=0;end;
0
 
LVL 1

Expert Comment

by:Gabor
ID: 1337594
Sorry nnn, but my CR-s disappeard. I don't know why.
0
 

Author Comment

by:nnn062397
ID: 1337595
More information to my problem:

1. The DLL have some units, and many units (DB) have exit procedures. My DLL has an exit procedure.

2. I wrote an interfaceing unit:
unit DLL_IF;
interface
function Valami( n: byte ) : byte;
implementation
function Valami( n: byte ) : byte; external 'MYDLL';
end.

This unit is linked somewhere in my program. The DLL is loaded with the EXE, and go away with it. It is no more present, but his and the unit exit procedures are not executed. (NT/win3x no but win95 yes)
How does work the DLL killing in Delphi? Or is it from system?
I must do something in program, to free the library?

My program works with an other interfaceing unit (included LoadLibrary & FreeLibrary).

Thanks
0
 
LVL 1

Expert Comment

by:Gabor
ID: 1337596
If you write a static unit to link your DLL Delphi only open it to you to access the procedures in it.Under Win95 the OS automatically closes the DLL after your application exits, this is why it executes the ExitProc.I could help you more if you wrote down what you want to do.(I think you have to be from Hungary, because you used 'Valami' as procedure name. If it's easier to discuss this in hungarian don't hesitate, because I'm from Hungary too :-))
0
 

Author Comment

by:nnn062397
ID: 1337597
OK!

Gábor, ettöl fejre fog állni az olvasótábor...

A probléma már csak elvi sikon izgat, mert sikerült megoldani a
LoadLibrary & FreeLibrary párossal; csak az hevit fel, hogy
az én commentemben megadott interface-eléssel nem birom
rávenni, hogy végrehajtsa a DLL-ben levö exitproc-okat.

Tehát még1x: a DLLemben kell használnom a DB unitot, annak
pedig van egy kilépö rutinja, ami felszabadit egy object-et.

Ha a programbol kilépek, a DLL-t is viszi magával, nincs benn
a memóriában, de csak w95 alatt indulnak be az exit eljárások.

Ha a fent megadott unitban kilépéskor használom az általad leirt
CloseDLL eljárást, ugyanaz történik, mint nélküle. Vagyis nem
pucol ki maga után...

Gyalog ki lehetne dobálni mindent, de ez nem valami elegáns...

Vili
non@dator.it
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question