Solved

Exit procedure in DLL

Posted on 1997-06-23
5
607 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

752 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