Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

C# and C++, Reading and writing from Text File

Status
Not open for further replies.

heem4745

Newbie level 3
Joined
Oct 3, 2008
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,305
Hi guys,

I'm currently working on a project which requires me to link both C++ and C# programs together. I've been trying to use a text file to link both of them together. Thing is I would like to confirm whether or not both programs could access the Text File together at the same time.

Basically, the C++ is supposed to write into the text file and the C# is suppose to read from it at the same time.

I heard under certain circumstances this may cause either programs to crash..... Any advice would be great.
 

wd5gnr

Newbie level 6
Joined
Jan 21, 2009
Messages
14
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,281
Activity points
1,411
This is usually not a good idea although with certain limitations you could get it to work. The problems are:

1) Can you open a file for both reading and writing at the same time?
2) The library and the operating system likely buffers some output, so at the very least you'd have to flush things.

What OS are you on? The correct ways to do this would be using pipes (which look like files) or shared memory (which has its own set of issues). Or if the programs are on different places think about sockets.

However, a more general question might be: What are you trying to accomplish?

Al W
https://www.hotsolder.com
 

heem4745

Newbie level 3
Joined
Oct 3, 2008
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,305
Well, I'm currently using windows Vista 32 bit. Thing is I wanted to link OpenCV with C#. This is the project I'm currently working on.

Right now I am testing to see whether or not my both programs, C++ and C# could be linked to one another using a text file. The main problem I am facing right now is whether or not letting my C++ program write and C# program to read at the same time is possible....
 

wd5gnr

Newbie level 6
Joined
Jan 21, 2009
Messages
14
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,281
Activity points
1,411
Well, like I say, expect that to be troublesome. If you expect them to read and write simultaneously. XP does have a bunch of IPC like pipes and mailboxes.

Here's an article: https://www.codeproject.com/KB/threads/Win32IPC.aspx

You'd be much better off with something like that. Another thing to think about would be to make a DLL out of one side and call it from the other (unless you are a managed app which I guess would be problematic).

Al W
https://www.hotsolder.com
 

sshahid47

Advanced Member level 4
Joined
Nov 5, 2004
Messages
101
Helped
15
Reputation
30
Reaction score
2
Trophy points
1,298
Activity points
974
you can do it the following ways

1) Use a file and map them in both the C++ and C# apps and use sync objects to signalling ( see msdn for file mapping and mutex objects)

2) use pipes at each end and communicate
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top