Solved

Exit procedure in DLL

Posted on 1997-06-23
5
595 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now