C++ CFile sharing with C# App not working? -


i'm having trouble getting file created , populated c++ application read different c# application while it's still open in c++ application.

i create file line:

txtfile.open(m_filename, cfile::modecreate | cfile::modewrite | cfile::sharedenywrite, &e) 

i've tried using lines:

txtfile.open(m_filename, cfile::modecreate|cfile::modewrite|cfile::sharedenynone, &e) 

and:

txtfile.open(m_filename, cfile::modecreate|cfile::modewrite, &e) 

with same results.

then in c# app i've tried 2 different ways of opening file:

filestream fs = file.openread(inputfilepath); byte[] buffer = new byte[fs.length]; fs.read(buffer, 0, buffer.length); fs.close(); 

and

byte[] buffer; using (filestream stream = new filestream(inputfilepath, filemode.open, fileaccess.read, fileshare.read)) {     buffer = new byte[stream.length];     stream.read(buffer, 0, buffer.length); } 

both methods catch error:

the process cannot access file 'filename.txt' because being used process.

the c++ app creates file, uses createprocess run c# app.

i expect issue in c# code try read file notepad gives no errors when add share permissions in c++ app, give errors when don't set permissions.

in end got work way wanted soonts' suggestion.

setting c++ fileshare option to:

txtfile.open(m_filename, cfile::modecreate|cfile::modewrite|cfile::sharedenywrite, &e) 

lets c# application read file, not write it.

in c# app reading file with:

using (filestream stream = new filestream(inputfilepath, filemode.open, fileaccess.read, fileshare.readwrite)) 

sets file access read only. setting file share permissions readwrite allows file opened while it's being written application. went wrong having fileshare permissions read conflicted c++ application before file opened. wouldn't open.

in c++, specify cfile::sharedenynone or cfile::sharedenywrite (like you're doing)

in c#, specify fileshare.write or fileshare.readwrite.


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -