Solved

Exit procedure in DLL

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

776 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