Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

handle in low-level function and API function

Status
Not open for further replies.

nevin2007

Programmer
Aug 21, 2009
31
IR
hi
How can i obtain HANDLE of file that already opened somewhere in my application ( i cant use PUBLIC variable because count and order of opening file sets by user)
I found this example that show list of opened file but the problem is handle in this database is different from fopen handle
 
What type of file are you talking about? A DBF, a text file, or what? And how are you opening it? With a USE statement, low-level file function, or what?

You mentioned FOPEN(). As you know, FOPEN() returns a handle that can be used in subsequent low-level file operations. Is that the kind of handle you are talking about.

If so, why not just store the value somewhere?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
thanks for your reply mike
As I said before my app use fopen and you know file type is not important for this function
Sometimes application may crash or generate an error just before saving handle in a file or STRTOFILE return an error like not disk space during saving file content (handle not shown in this function) or you want to close all file without closing database (CLOSE ALL- close file and databse). The above example show a table that contain list of open file by current process but the problem is
Visual FoxPro hides real file handle values. The FOPEN() returns the value from internal FoxPro table, not the value assigned by the OS


thanks
 
Nevin2007,

I've re-read your original question and also your reply, but my poor brain is getting tired, and I can't make sense of it. Sorry.

However, you're right that the handle returned by FOPEN() is internal to FoxPro, and has nothing to do with the one assigned by the OS.

If you really need to work with the OS-assigned handle, you will have to use API calls to work with the file. Use FileOpen to open it, ReadFile to read it, and so on. See to get started.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
I've never had the wish to CLOSE ALL, neither for files opened by FOPEN nor the database. If VFP crashes, it crahses anyway, there's little you can do about that, the OS will get rid of handles.

There is a lot of tidying up done when the VFP runtime closes, eg you don't need to RELEASE ALL, CLOSE ALL even in a normal shutdown/exit of your application, it's done anyway.

In normal routines writing files the opening and closing is encapsuled in a class or other object knowing everything it needs to know, I always think in this kind of encapsulation and not in the form of procedural/functional code.

So in my case typical code fopening a file is also fcloseign it. If it really crashes the typical things like a destroy event or a clear events will not run anyway. If the vfp runtime eg crashes with C5 there is no pont in having any exit code.

Bye, Olaf.
 
Olaf is correct.

Either your Application has CRASHED or you have detected an Error and are using your own FUNCTION to handle error processing prior to shutting down.

If your Application has CRASHED, there is nothing to do. All Open objects will be closed when Windows releases VFP.

If your Application has vectored off to an error handling utility within your application, then the handles, if saved, are still available to use with FCLOSE().

You can always do a search of the Windows tasks which are running upon launching certain routines and close anything that you believe might be a left-over. ( faq184-5470 & faq184-4140 )

Good Luck,
JRB-Bldr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top