Solved

Trouble closing a file

Posted on 2000-05-17
6
152 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
Technology Partners: 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
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…

737 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