Page 1 of 1

Communication Through Text file

Posted: April 26th, 2012, 9:10 pm
by LuX
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);

Re: Communication Through Text file

Posted: April 26th, 2012, 9:28 pm
by Dlotan
open it again?

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

Re: Communication Through Text file

Posted: April 27th, 2012, 6:06 am
by chili
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.

Re: Communication Through Text file

Posted: April 27th, 2012, 10:32 am
by LuX
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!

Re: Communication Through Text file

Posted: April 27th, 2012, 2:09 pm
by chili
Yeah long weekend! I got three days off myself. I feel another lesson or maybe even two coming on. 8-)