Link to home
Start Free TrialLog in
Avatar of ardolino
ardolino

asked on

File Handles in Mixed Language Programming

I need a way to figure out how to obtain a listing of all files and there associated handles that a program has open at any given time during program execution.  I need this because I am opening, reading, writing, and closing my files in Fortran, but I am locking and unlocking records in these files using C++ (the original LOCKING routine was eliminated by Microsoft when they created Fortran Powerstation).  Anyway, I'm using Microsoft Developer Studio in conjuction with Visual C++ and Fortran Powerstation.  There is no way in Fortran that I know of to obtain the handles of the files that it opens.  Is there any other way I can get these handles?  This will be a tough question, I think.  It must be stored somewhere in some type of table, no?
Avatar of JYoungman
JYoungman

My FORTRAN is a bit rusty now but it seems to me that the most convenient approach would probably be to WRITE your data into CHARACTER*(*) variables and then pass these to a C++ routine to do the actual I/O, and hence avoid opening the files from FORTRAN.  I know it's sometimes difficult to pass a CHARACTER*(*) to another language, so you may have to use a CHARACTER*(nnn) instead.

If this just isn't possible, then I suggest you use two files.  One ('FOO.DAT') is the one against which you do I/O from FORTRAN, and the other ("FOO.LCK") is the one against which you do the locking and unlocking from C++.  

Avatar of ardolino

ASKER

My problem is that I am doing a mass conversion of over 1000 programs written in FORTRAN that already having external function calls to lock and unlock records in a file, but all of the programs open, read, write, and close the files directly.  If I could just obtain the handle of the file, I can replace the lock and unlock functions with c++ routines that can actually lock and unlock the files.  (The original FORTRAN lock and unlock routines used the FORTRAN LOCKING command (no longer available)).  If I can't get the handle, then I can always work something out with using two files, but if there is a way to get the handle, it would be a lot easier for me, even if getting the actual handle may be difficult.  There has to be a way to get it, no?
Yes, I assume there is *some* way to get it.  I don't have a copy of PowerStation here, and I'm currently booted to Linux, so I can't even search the MSDN library (since the MSDN library program only runs under Windows).  I could tell you how to do it under Linux with g77 if you like :-)    But seriously, I don't know how to get the file handle and don't have access to the relevant reference material at the moment.

Does this locking need to take place between machines over a network, or just on one machine?


I found a utility called File Monitor for Win95 and WinNT - it has source code, but I'm having a little trouble understanding it.  I'll figure it out, though - it does what I want to do.
Can you post the URL where this utility is obtainable from?
ASKER CERTIFIED SOLUTION
Avatar of Answers2000
Answers2000

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
locking and unlocking need to be done synchronously.  The change notification system is goig to opperate asynchronously.  VERY asynchronously.