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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to open same file in two different processes

Status
Not open for further replies.

youbbi

Programmer
Mar 14, 2007
1
US
I am using Visual Studio 6.0 Professional. I am receving a video file by the network by listening to a specified socket. I am creating a file and writing those packets in it. I have a thread that creates and writes to file and I have another thread that open Windows media player with filename path specified. The command I use is:

system(cmd); //string cmd = "wmplayer.exe" + filename

The proble is that when wmplayer tries to open the file, it says it is already in use. But my application needs to open the file to continuously write the data being received. (I am streaming a video feed from another computer and I want to be able to play it while I am still receiving packets).

To open the file, I am doing:

FILE *pVideoFile;
fp = fopen(DEST_FILENAME, "wb+");

Is there a way to create a file that has no protection access so that Windows player will accept to open it while I am writing in it.
 
I'm not sure if fopen() locks the file when you open it, but you can try using sopen() to open it for sharing.
 
Hmm..Why not using MFC

Use CFile with CFile::shareDenyNone as one of the options.

Opens the file without denying other processes read or write access to the file. Create fails if the file has been opened in compatibility mode by any other process.

 
VCVCVCTekTips said:
Why not using MFC
Probably because MFC sucks. :p

I only use MFC if I have absolutely no other choice.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top