Link to home
Start Free TrialLog in
Avatar of rbohac
rbohac

asked on

Open a file for writing while allowing access ro another application for reading

Hello,

This is kind of a complex situation, but bascially I have a DLL written in C++ that opens a file to allow voice hardware to write an audio stream to it. right now it opens the file with the following flags: O_BINARY | O_RDWR | O_CREAT

What I need to be able to do is read the file from a different application, while the file is still open for writing by the DLL. I do have the ability to change the DLL.

First of all, is this possible, and second of all, what do I need to change to allow this?

The secondary application is written in Delphi, and I myself am more of a Delphi programmer.
ASKER CERTIFIED SOLUTION
Avatar of Axter
Axter
Flag of United States of America image

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
Have your DLL application open the file in shared mode.
Example:
fh2 = _open( "data.txt", _O_WRONLY | _O_CREAT, _S_IREAD);


Then your other application should be able to open it for reading
Avatar of rbohac
rbohac

ASKER

Great! I will try that now.

Also if you want more of a background on what I am doing with this.. I originally asked the question in the Delphi Q...
https://www.experts-exchange.com/questions/21122991/Streaming-a-buffer-while-it-is-being-written.html
>>The secondary application is written in Delphi, and I myself am more of a Delphi programmer

The secondary application does have to do anything special, as long as the DLL opens the file in shared mode.
You can also use the _sopen function to open a file for sharing.

Also many of the Windows API file functions have sharing options.
Avatar of rbohac

ASKER

Well, unfortunately not. I am limited by the API for the driver/hardware that I am using. It requires that upi call their open function..
http://resource.intel.com/telecom/support/hmp10/docs/htmlfiles/pgmgd3/1456-04-87.html

I should have the results of your first comment here in a few minutes
Avatar of rbohac

ASKER

Well, it doesn't seem as though that worked.

I looked at the windows explorer and noticed that the file icon with semi-transparent with an overlay of a black clock icon
>>Well, it doesn't seem as though that worked.

Please explain exactly how it's not working.
Also, post your new code, so that we can verify correct implementation.
Avatar of rbohac

ASKER

Actually going through tha I think I figured it out.. The API is buffering the data before it writes it. The file gets created, but it is 0 bytes for about the first 10 seconds. After some data is written, I can open it just fine.