Solved

File Handles in Mixed Language Programming

Posted on 1998-08-03
7
206 Views
Last Modified: 2013-11-08
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?
0
Comment
Question by:ardolino
7 Comments
 
LVL 2

Expert Comment

by:JYoungman
ID: 1169302
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++.  

0
 

Author Comment

by:ardolino
ID: 1169303
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?
0
 
LVL 2

Expert Comment

by:JYoungman
ID: 1169304
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?


0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:ardolino
ID: 1169305
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.
0
 
LVL 11

Expert Comment

by:alexo
ID: 1169306
Can you post the URL where this utility is obtainable from?
0
 
LVL 8

Accepted Solution

by:
Answers2000 earned 200 total points
ID: 1169307
FindFirstChangeNotification and FindNextChangeNotification allow you to monitor changes to a directory tree from a C++ program.  Assuming you know where the Fortran program writes files, the C program can monitor this area and take corresponding action (placing the locks for example).


0
 
LVL 22

Expert Comment

by:nietod
ID: 1169308
locking and unlocking need to be done synchronously.  The change notification system is goig to opperate asynchronously.  VERY asynchronously.  
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now