Solved

Trouble closing a file

Posted on 2000-05-17
6
153 Views
Last Modified: 2010-04-04
I'm running a dll from d5 that sometimes aborts before closing a file.  I don't have anyway within the dll to clean up things.   Is there a way from d5 to close the file?   I general run the dll many times from d5 but have to restart my d5 program if the dll aborts.

It's no problem detecting and trapping the openfile problem but I don't know how to clean things up from d5 without restarting the d5 program.  Any help would be appreciated.
0
Comment
Question by:sartwj
[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
6 Comments
 
LVL 1

Expert Comment

by:sistudio041900
ID: 2817214
there are 2 things to help you D5help

Reset(F);

try
 ...  // process file F
finally
  // will always be called, even if code
  // after try fails
  CloseFile(F);
end;

finalization

will be called when Dll unloads, make sure you close all open files








0
 
LVL 3

Expert Comment

by:smurff
ID: 2817496
Ive had a similar problem, i used this:


procedure KillApp(title : string);
var h : HWND;

begin
h:=FindWindow(nil,@(title)[1]);
if h<>0 then
        begin
        SendMessage(h,WM_CLOSE,0,0);
        Showmessage('App terminated.')
        end
        else
        Showmessage('failed kill app.')
end;

//to close notepad,
KillApp('Notepad');
Hope this helps
Smurff
0
 

Author Comment

by:sartwj
ID: 2817767
smurff,

Unfortunately by the time I make a check on the opened file I've already performed a FreeLibrary() on the dll so FindWindow always returns 0.  The only thing left open is the improperly closed file.  I've also tried leaving the dll open until I'm completely done with it and let your procedure KillApp stop the dll when needed, but that doesn't do it either.   Any other ideas.
0
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!

 
LVL 20

Expert Comment

by:Madshi
ID: 2820097
Is it your own dll? Do you have the sources?
0
 

Author Comment

by:sartwj
ID: 2821277
I own the dll - it's a large FORTRAN program compiled as a dll.  When it works, it works well.  But when it fails...it leaves opened files in limbo.

I've never found the right compiler options (on the FORTRAN side) to ignore fatal errors and just close normally.
0
 
LVL 20

Accepted Solution

by:
Madshi earned 100 total points
ID: 2821614
Okay, you will probably not like this idea, but it should work:
How about writing another very little executable, that does nothing but take some parameters and load/unload that fortran dll? Your main executable could then execute that other mini executable. When the mini executable finishes, all handles are automatically closed by Windows.

Regards, Madshi.
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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

717 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