Communication Through Text file

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Communication Through Text file

Post by LuX » April 26th, 2012, 9:10 pm

Yeah...

I made the chili framework communicate with a text file, so that depending on the text, eg. "1" will move the character to the right, "2" down, etc... And it works! Even if I have it open, change the text and quickly hit crtl + s. The problem comes with VB. I tried to make this control interface with buttons where the framework would be the "screen" like the pipboy in fallout 3, and have control buttons on the VB form around it.

Thing is, c++ stops looking for the file as soon as I edit it through VB, as VB, I believe, edits text files so that it deletes them and remakes it.

So my question is; how will I make c++ look for the text file again?

This is the code:

Code: Select all

	//Begin load info
	int readline[100];
	readline[0] = 0;
	int readx = 1;
	fstream textfile;
	textfile.open("data.txt");
	textfile >> readline[readx];
	if (readline[1] == 1)
	{x += 1;}
	else if (readline[1] == 2)
	{y += 1;}
	else if (readline[1] == 3)
	{x -= 1;}
	else if (readline[1] == 4)
	{y -= 1;}
	textfile.close();
	//End load info

	DrawDude(x, y);
ʕ •ᴥ•ʔ

Dlotan
Posts: 32
Joined: April 10th, 2012, 4:58 pm

Re: Communication Through Text file

Post by Dlotan » April 26th, 2012, 9:28 pm

open it again?

edit: btw u should communicate using sockets between programs... or use a database which has a management system for multible access

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Communication Through Text file

Post by chili » April 27th, 2012, 6:06 am

Inter-process communication is a pretty advanced topic LuX. It's probably not impossible to do it with shared disk files, but it's definitely not the best or easiest solution. You'd probably need to forget about iostream and use the WIN32 native file access routines on the C++ side, and you'd also have to worry about the specific behavior of whatever implementation you're using in vb.net.

Sockets would most likely be the easiest for you to try. Registered messages is something I might try myself in a similar situation.
Chili

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: Communication Through Text file

Post by LuX » April 27th, 2012, 10:32 am

Hmm... I guess that would be a bit too hard for now. Haven't really dared to mess with the registry yet, if that's what you mean.

Oh yeah! four days of holiday! Time to mess with c++ big time!
Happy -whatever the day is called in English, if you celebrate it in your country- day!
ʕ •ᴥ•ʔ

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Communication Through Text file

Post by chili » April 27th, 2012, 2:09 pm

Yeah long weekend! I got three days off myself. I feel another lesson or maybe even two coming on. 8-)
Chili

Post Reply