4 Replies - 833 Views - Last Post: 02 July 2009 - 07:11 PM Rate Topic: -----

#1 shortymant  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 17-June 09

if loop always returns false

Posted 02 July 2009 - 03:06 PM

I am building a rather simple program for a friend. Although, I am stuck at this annoying part.

Here is my code.
using namespace std;

string myStrng;
string myStrng2;
string myDirectory;
string myDirectory2;

int main()
{
	int myFinder;
	int myFinder2;
	basic_string<TCHAR> myDirectory;
	cout << "Type in the default path to your server files.\n\n";
				getline(cin, myDirectory);
				Sleep (800);
				cout << "\n\n";
				cout << "So the server files are in " << myDirectory << " Is that correct? y/n  ";
				getline(cin, myStrng2);
				myDirectory2 = myDirectory + "\\MatchAgent\\MatchAgent.exe";
				myDirectory = myDirectory + "\\MatchServer\\MatchServer.exe";
				
				
				if (myStrng == "y" || myStrng == "Y")
				{
							
							cout << "\n\n";
							cout << "O.k, Keeper will now keep an eye on your MatchServer + MatchAgent. " << endl;
							}
							loop1:
						   myFinder = PostMessage (FindWindow(0, "MatchServer - MatchServer1"), NULL, 0, 0);
						   myFinder2 = PostMessage(FindWindow(0, "MatchAgent - MatchAgent1"), NULL, 0, 0);
							
							if (myFinder == false)
							{
										 cout << "MatchServer Crashed!\n";
										 cout << "Now opening MatchServer!\n";
										 ShellExecute(NULL, "open", myDirectory.c_str(), NULL, NULL, SW_SHOW);
										 Sleep (6000);
										 cout << "Now opening MatchAgent!\n\n";
										 ShellExecute(NULL, "open", myDirectory2.c_str(), NULL, NULL, SW_SHOW);
										 Sleep (2000);
										 goto loop1;
										 }
							if (myFinder == true)
							{
										 goto loop1;
										 }



It compiles fine, runs smooth. However, my program thinks that "MatchServer - MatchServer1" && "MatchAgent - MatchAgent1" is always closed, and probably attempting to open it again. (These 2 programs do not allow more than 1 of itself to open.)

I know I can use the PID, but this is just a beta until I decide to put in a .ini reader/writer.
P.S: WinExec() didn't work so well, so I reverted back to ShellExecute() for now.

Is This A Good Question/Topic? 0
  • +

Replies To: if loop always returns false

#2 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1072
  • View blog
  • Posts: 4,532
  • Joined: 09-June 09

Re: if loop always returns false

Posted 02 July 2009 - 03:28 PM

what are you typing in for your current directory
Was This Post Helpful? 0
  • +
  • -

#3 shortymant  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 17-June 09

Re: if loop always returns false

Posted 02 July 2009 - 03:36 PM

View PostImaSexy, on 2 Jul, 2009 - 02:28 PM, said:

what are you typing in for your current directory

C:\\Server

The whole path is:
C:\Server\MatchServer\
And
C:\Server\MatchAgent\
Was This Post Helpful? 0
  • +
  • -

#4 Guest_c.user*


Reputation:

Re: if loop always returns false

Posted 02 July 2009 - 06:48 PM

separate PostMessage and FindWindow and look what does FindWindow return

myFinder = PostMessage (FindWindow(0, "MatchServer - MatchServer1"), NULL, 0, 0);

	/* here define value, I don't know its type, try unsigned long */
	unsigned long value;

	value = FindWindow(0, "MatchServer - MatchServer1");
	cout << value 
		 << endl;
	myFinder = PostMessage(value, NULL, 0, 0);
	cout << myFinder 
		 << endl;



also you do
	getline(cin, myStrng2);
	
	...

	if (myStrng == "y" || myStrng == "Y") {


I think you wanted to do them equal

This post has been edited by c.user: 02 July 2009 - 06:50 PM

Was This Post Helpful? 0

#5 shortymant  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 17-June 09

Re: if loop always returns false

Posted 02 July 2009 - 07:11 PM

View Postc.user, on 2 Jul, 2009 - 05:48 PM, said:

separate PostMessage and FindWindow and look what does FindWindow return

myFinder = PostMessage (FindWindow(0, "MatchServer - MatchServer1"), NULL, 0, 0);

	/* here define value, I don't know its type, try unsigned long */
	unsigned long value;

	value = FindWindow(0, "MatchServer - MatchServer1");
	cout << value 
		 << endl;
	myFinder = PostMessage(value, NULL, 0, 0);
	cout << myFinder 
		 << endl;



Thank you for helping, but I am getting an error about unsigned long, int, string, or anything else if I attempt to do:
value = FindWindow(0, "MatchServer - MatchServer1");



Invalid Conversion from HWND__* to unsigned long int.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1