Re: c++ to launch a program
That cannot be done with C++, you have to use the Win32 API (which should be available since you want to start the target application in Win98 compatibility mode). Your problem can be solved with 3 steps:
1) set up an environment block for the new process. You can read the current environment settings by calling GetEnvironmentStrings and copy them to the new environment settings
2) set the __COMPAT_LAYER variable to Windows98
3) call CreateProcess with the appropriate parameters (providing the newly created environment settings)
Re: c++ to launch a program
Unless you have any extra needs, the appropriate solution would be a shortcut. Eventually a batch.
Re: c++ to launch a program
You could write a batch programmatically and launch it with CreateProcess
Code:
STARTUPINFO si = { 0 };
si.cb = sizeof(si);
si.showWindow = SW_HIDE;
PROCESS_INFO pi = { 0 };
std::ofstream batch("temp.bat");
batch << "@echo off" << std::endl
<< "set __COMPAT_LAYER=Win98" << std::endl
<< executable_to_invoke << std::endl;
batch.close();
CreateProcess(NULL, "call temp.bat", NULL, NULL, FALSE,
DETACHED_PROCESS, NULL, NULL, &si, &pi);
...
where 'executable_to_invoke' is a string variable that contains the filename (full path if not in working directory) of the executable you want to launch.
After CreateProcess you could wait for the process handle pi.hProcess (calling WaitForSingleObject) if your launcher should wait until execution of the batch has ended. If not, you at least may wait until the executable was launched from batch, e. g. by enumerating windows or processes until you found the newly started program. If you could retrieve the window handle of the new process that way, you also could call 'ShowWindow(hwndProc, SW_MAXIMIZE);' to get it maximized.
Regards, Alex
Re: c++ to launch a program
Thanks for the input so far. I did make a batch previously which launches the program maximized, but I don't know how to set compatibility mode in a batch file... and a seemingly minor but important issue is the fact that the command prompt flashed up on the screen for a second before the program launches. This is a commercial product I am producing and that will sort of undercut the professional veneer. If I can get past those two issues somehow (compatibility mode and the flashing command prompt) I would be happy to just use a batch file for this.
Re: c++ to launch a program
I have managed to grasp what you put in front of me regarding the compatibility mode now (sorry). And it works great. Any ideas about how to prevent the command prompt from briefly flashing before the program launches?
Re: c++ to launch a program
Quote:
Originally Posted by
autodale
I have managed to grasp what you put in front of me regarding the compatibility mode now (sorry). And it works great. Any ideas about how to prevent the command prompt from briefly flashing before the program launches?
You can either omit the batch file at all and follow the approach I advised in my previous approach or specify a window coordinate where the command window cannot be seen. Use the dwX, dwY and dwFlags Attributes.
Re: c++ to launch a program
I would try what you suggested previously but it's beyond my understanding of c++. I'm just a newbie who was wondering if it could be done in a few simple lines.
Re: c++ to launch a program
Quote:
Originally Posted by
autodale
I have managed to grasp what you put in front of me regarding the compatibility mode now (sorry). And it works great. Any ideas about how to prevent the command prompt from briefly flashing before the program launches?
Did you try the CreateProcess with the DETACHED_PROCESS creation flag? The DETACHED_PROCESS flag should prevent the console window to be shown.
Regards, Alex