?
Solved

Trouble closing a file

Posted on 2000-05-17
6
Medium Priority
?
154 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 400 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

770 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