Skip to main content
GameDev.net gamedev.net
🔒 Locked

Coding a shortcut?

Started by RedRabbit Sep 12, 2004 at 2:52 PM 14 replies 1.9k views
Original Post
RedRabbit
RedRabbit
Hey guys im trying to mess around with diablo II and I want to make a .exe that will open DiabloII.exe can anybody help me out (ps this isnt for *hacking* i am just trying to learn C++ in as many ways as possible....this is actually for a lazy mans needs i want to be able to type something such as !log in game and have the program log everything I type in the game in a .txt file until i type like !stop; its so I can avoid alt+tabbing when i take down peoples emails and such. thanks!)
//-----------------------------------------One short sleepe past, wee wake eternally, And Death shall be no more, Death thou shalt die.
Oluseyi
Oluseyi
Look up the following families of functions:
CreateProcess[Ex]
spawn
exec
Pipo DeClown
Pipo DeClown
Quote:
Original post by Oluseyi
Look up the following families of functions:
CreateProcess[Ex]
spawn
exec


I recommend using the _exec-family, because the parameters actually WORK. I've had trouble using more than 1 parameter with the other functions.

Clicky!
Pete_
Pete_
Or if you want to stay within the Standard you could try std::system(). It doesn't give you that much control but might be sufficient if you don't have complex needs.

- Pete
Pipo DeClown
Pipo DeClown
No! No no no! USE _EXECx()!!
It's the best for launching games with parameters.

(Check my post aboce for a link!)
Oluseyi
Oluseyi
Problem: std::system blocks the parent process, which means that you can start the subprogram and then continue work in the parent. The others are non-blocking. For Windows, I prefer CreateProcessEx because of the level of control it provides.
RedRabbit
RedRabbit
i appreciate the responses but the description at the dev site is really confusing...can anybody give me a somewhat "lame-mans" example/explanation? thanks :)
//-----------------------------------------One short sleepe past, wee wake eternally, And Death shall be no more, Death thou shalt die.
Pipo DeClown
Pipo DeClown
// crt_args.c/* Illustrates the following variables used for accessing * command-line arguments and environment variables: * argc  argv  envp * This program will be executed by crt_exec which follows. */#include <stdio.h>int main( int argc, /* Number of strings in array argv */ char *argv[],       /* Array of command-line argument strings */ char **envp )       /* Array of environment variable strings */{    int count;    /* Display each command-line argument. */    printf( "\nCommand-line arguments:\n" );    for( count = 0; count < argc; count++ )        printf( "  argv[%d]   %s\n", count, argv[count] );    /* Display each environment variable. */    printf( "\nEnvironment variables:\n" );    while( *envp != NULL )        printf( "  %s\n", *(envp++) );    return;}


.. is from that website. But it got scrambled, so I copied it and pasted it here. It's cool here.

[VERY LATE edit] Oh now I see it's wrong code.

[Edited by - Pipo DeClown on September 16, 2004 12:18:24 PM]
RedRabbit
RedRabbit
im still confused....how would i implement that with opening d2.exe? (im sort of new to working with files)
//-----------------------------------------One short sleepe past, wee wake eternally, And Death shall be no more, Death thou shalt die.
RedRabbit
RedRabbit
it might help you all to know I only know C++ not c....and this is written in c (does it matter?) it runs but I dont understand what its opening and where its doing it in the code :/
//-----------------------------------------One short sleepe past, wee wake eternally, And Death shall be no more, Death thou shalt die.
Pipo DeClown
Pipo DeClown
I'm soooooooooo incredibly sorry for providing the wrong sourcecode. If you still have the need/interest, reply here, I'll get some working code.
RedRabbit
RedRabbit
its ok dude...yes im still in need :P
//-----------------------------------------One short sleepe past, wee wake eternally, And Death shall be no more, Death thou shalt die.
Pipo DeClown
Pipo DeClown
// Very basic _execv - example#include <process.h>int main(){   char *args[4];   args[0] = "d2.exe";   // Executable file   args[1] = "windowed"; // Argument 1   args[2] = "1";        // Argument 2   args[3] = NULL;       // Always end with NULL    _execv( "d2.exe", args ); // Executable file, arguments list    /*      -Note that the executable file is passed twice (once as cmd and one as argument).      -The arguments list should end with NULL.      -Try different arguments, if this style doesn't work ("windowed","1" => "windowed 1").    */}


This _should_ work. I haven't found time to compile it yet.
RedRabbit
RedRabbit
// Very basic _execv - example#include <process.h>#include <fstream>int main(){   char *args[4];   args[0] = "C:'\'Program Files'\'Diablo II'\'Diablo II.exe";   // Executable file   args[1] = "windowed 1"; // Argument 1   args[2] = "windowed 1";        // Argument 2   args[3] = NULL;       // Always end with NULL    _execv( "Diablo II.exe", args ); // Executable file, arguments list    /*      -Note that the executable file is passed twice (once as cmd and one as argument).      -The arguments list should end with NULL.      -Try different arguments, if this style doesn't work ("windowed","1" => "windowed 1").    */}


this is what I have now...ive tried using args 2 and 3 as the following:
1: windowed 1/Normal window/Maximized/Minimized
2: 1,Normal window/windowed 1/Maximized/Minimized/windowed/NULL

Ive also tried giving full and partial paths to the Diablo II.exe directory in both spots :-/

none work....help plz? :)
//-----------------------------------------One short sleepe past, wee wake eternally, And Death shall be no more, Death thou shalt die.
Pipo DeClown
Pipo DeClown
#include <process.h>#include <fstream>int main(){   char *args[4];   args[0] = "C:\\Program Files\\Diablo II\\Diablo II.exe";   args[1] = "windowed";   args[2] = "1";   args[3] = NULL;    _execv( "C:\\Program Files\\Diablo II\\Diablo II.exe", args );}


Changes:
1) \\ is \ in a char array.
2) I put absolute paths.
3) I used the arguments "" and "windowed" and "1".
RedRabbit
RedRabbit
well i tried it on Steam.exe (for HL + HL Mods) and it works....(the new code does) thanks a lot man time to tinker around with this
//-----------------------------------------One short sleepe past, wee wake eternally, And Death shall be no more, Death thou shalt die.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.