[C++ Help!]I got problem in my code...

Status
Not open for further replies.

AKIRADEATH

Veteran
Original poster
veteran
senior
member
Joined
Jul 27, 2011
Posts
5,352
Reaction score
1,260
Points
192
Hello!
I'm making a Launcher for my game and I need help with... *eats a biscuit* ...the Code that executes the game.My code is here:
Code:
if System("C:\test.exe"); 
                 {exit (1);}
                 else
                 {MessageBox::Show("Failed to Execute Operation 23:Crazy Warfare.\nMake sure you have installed OP23:CW correctly.", "Failed to Execute Operation 23:Crazy Warfare!", MessageBoxButtons::OK, MessageBoxIcon::Error); exit (1);}

Errors I get:
Code:
1>------ Build started: Project: OP23CW Launcher, Configuration: Debug Win32 ------
1>  OP23CW Launcher.cpp
1>c:\documents and settings\thanasis14.tha_14\τα έγγραφά μου\visual studio 2010\projects\op23cw launcher\op23cw launcher\Form1.h(106): error C2061: syntax error : identifier 'System'
1>c:\documents and settings\thanasis14.tha_14\τα έγγραφά μου\visual studio 2010\projects\op23cw launcher\op23cw launcher\Form1.h(108): error C2181: illegal else without matching if
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


I will appreciate it if you could help me.
 

TheSyndicate

0110100001101001
veteran
senior
member
Joined
May 22, 2011
Posts
2,287
Reaction score
1,345
Points
151
Age
29
Location
Texas
Putting a semicolon after an if statement is a syntax error and will not compile, it should look something like:

Code:
if(a == 10)
{
     //code here
}

else
{
     //code here
}

Here's what cplusplus.com says about "System()"

The value returned when the argument passed is not NULL, depends on the running environment specifications. In many systems, 0 is used to indicate that the command was successfully executed and other values to indicate some sort of error.
When the argument passed is NULL, the function returns a nonzero value if the command processor is available, and zero otherwise.

So, your first if statement should be:

Code:
if(System("C:\test.exe") == 0)
{
     //successful
}

else
{
     //unsuccessful
}

Also, what's up with your MessageBox code? Looks like you're trying to use C# code. Are you using a library? If not, the standard MessageBox that is defined in Windows.h is:

Code:
MessageBox(hwnd, LPCTSTR text, LPCTSTR caption, uint);

You could use it like so:

Code:
MessageBox(0, "Hello world!", "Some caption here", MB_OK);
 
  • Like
Reactions: AKIRADEATH

AKIRADEATH

Veteran
Original poster
veteran
senior
member
Joined
Jul 27, 2011
Posts
5,352
Reaction score
1,260
Points
192
Thanks Sooooo MUCH!!
Also The messageBox is working just great as I wanted.
Thanks again!
 
  • Like
Reactions: TheSyndicate

TheSyndicate

0110100001101001
veteran
senior
member
Joined
May 22, 2011
Posts
2,287
Reaction score
1,345
Points
151
Age
29
Location
Texas
You're welcome. If you ever need any help, feel free to shoot me a PM. I'll be more than happy to help you out.
 
Status
Not open for further replies.