can I return values from some other exe file?

This is a discussion on can I return values from some other exe file? within the C++ Programming forums, part of the General Programming Boards category; Im making this bad mudgame, just to learn c++ while doing sometjhing, and I came to a problem. I have ...

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    25

    can I return values from some other exe file?

    Im making this bad mudgame, just to learn c++ while doing sometjhing, and I came to a problem. I have made enemies in a nother file. and I tryed using header files, bu that diddnt work like planed so I tryed running em in a nother .exe file, and need to return if you won or not...

    Code:
    system("fight.exe") if (result == '1')
           {
            mob = '0' 
            win++;
            }
    or something like that, but it requires that I get the result back from fight.exe is that possible?

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Yes its possible. You'd have to capture the return value of system() though.

    I would recommend against it and would instead look to see what problem(s) you had with the header file.

  3. #3
    Registered User
    Join Date
    Oct 2004
    Posts
    25
    well.. I am a newbie at this:P and my problem with the header file is that I use goto in my program. to go to diffrent "rooms" and fierent enemy's. and I cant type goto inside the headerfile to goto somewhere in the main file. and I cant goto <variable>..

    or at least I dont think I can, cant make it work.

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    Use ShellExecuteEx() to execute the other exe. Then use WaitForSingleObject() to wait for that process to end. Then use GetExitCodeProcess() to get the exit code for that process.

  5. #5
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    Question Is that what you REALLY want to do?

    Do you really want two exe files? Or, do you want to make ONE exe file from multiple source & header files???

    If that's what you want, see the Programming FAQ.

  6. #6
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Quote Originally Posted by boozy
    well.. I am a newbie at this:P and my problem with the header file is that I use goto in my program. to go to diffrent "rooms" and fierent enemy's. and I cant type goto inside the headerfile to goto somewhere in the main file. and I cant goto <variable>..

    or at least I dont think I can, cant make it work.
    Ok burn whatever books you have been learning from. There is no need to use goto so excessivly.

  7. #7
    Registered User
    Join Date
    Oct 2004
    Posts
    25
    No but its the only way I have gotten the fight, and the rooms to work in the same program unless I had all the code in the same .cpp file.. yes I know I dont need to use that many goto in one file:P but... if I dont, it wont work.. hehe. so Ill just try some more with header files, besides its allways good to know how to get info from an .exe file.

    thanks for the help

  8. #8
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    In all honesty you need to stop with the game and learn more about the language first. Its fairly obvious your knowledge isn't at the level needed to do what you want and do it well.

  9. #9
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    Quote Originally Posted by Thantos
    Yes its possible. You'd have to capture the return value of system() though
    I thought system() only returned 1 or 0 depending on if the call it executed returned with or without an error code...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  10. #10
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    From the man page for system():
    The value returned is -1 on error (e.g. fork failed), and the return status of the command otherwise.
    Last edited by Thantos; 10-22-2004 at 09:32 AM. Reason: Stupid swear filter

  11. #11
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    Quote Originally Posted by Thantos
    From the man page for system():
    oic... btw... what's with the swear filter kicking on in the middle of status? or is that something you did?
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  12. #12
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    it didn't like the - (dash) that man had due to line wrapping.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. New string functions
    By Elysia in forum C Programming
    Replies: 11
    Last Post: 03-28-2009, 06:03 AM
  2. Replies: 8
    Last Post: 03-10-2008, 12:57 PM
  3. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  4. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  5. OpenGL and Windows
    By sean345 in forum Game Programming
    Replies: 5
    Last Post: 06-24-2002, 11:14 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21