Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Using CreateProcess to launch games

Posted on 2000-03-11
8
Medium Priority
?
385 Views
Last Modified: 2013-12-03
I use CreateProcess to launch games like Unreal Tournament, Quake, etc...

Some games do not start properly. They just close before being fully launched. I even change the directory to the game directory. Could someone tell me what the best values for the flags would be for these games ?

I use the following code.

procedure TFormMainMenu.LaunchApplication(pFileName: string; var pThreadId, pThreadHandle: DWORD);
var
  zAppName: array[0..512] of char;
  StartupInfo: TStartupInfo;
  ProcessInfo: TProcessInformation;
begin
  ButtonQuit.Enabled := False;
  fLaunchingApplication := True;
  try
    StrPCopy(zAppName, pFileName);
    FillChar(StartupInfo, Sizeof(StartupInfo), #0);
    StartupInfo.cb := Sizeof(StartupInfo);
    StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
    StartupInfo.wShowWindow := SW_NORMAL;
    if CreateProcess(nil,
                     zAppName, { pointer to command line string }
                     nil,      { pointer to process security attributes }
                     nil,      { pointer to thread security attributes }
                     True,    { handle inheritance flag }
                     CREATE_NEW_CONSOLE, { creation flags }
                     nil,      { pointer to new environment block }
                     nil,      { pointer to current directory name }
                     StartupInfo,  { pointer to STARTUPINFO }
                     ProcessInfo) then { pointer to PROCESS_INF }
    begin
      WaitForInputIdle(ProcessInfo.hProcess, 300000);
      pThreadHandle := ProcessInfo.hThread;
      pThreadId := ProcessInfo.dwThreadId;
    end
    else
    begin
      pThreadHandle := 0;
      pThreadId := 0;
    end;
    // The handle to the process is needed to see if the application is still
    // active.
    CloseHandle(ProcessInfo.hProcess);
  finally
    ButtonQuit.Enabled := True;
    fLaunchingApplication := False;
  end;
end;
0
Comment
Question by:alexandram
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 32

Accepted Solution

by:
jhance earned 800 total points
ID: 2608544
For a Windows GUI application (i.e. non-console), you don't want to set the dwCreationFlags to CREATE_NEW_CONSOLE.  Just make this parameter 0.

When you're done with CreateProcess, don't use WaitForInputIdle to keep tabs on in.  Use WaitForSingleObject and you will get signaled with the program exits.
0
 
LVL 22

Expert Comment

by:nietod
ID: 2608689
And close the thread handle too.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 2611658
I recommend using ShellExecuteEx to start the original shortCut (*.lnk) that the game setup installed. Perhaps there are some special settings in the shortCut which are needed to start the game correctly. Starting the lnk-file with ShellExecuteEx will be exactly the same as if the user had double-clicked the lnk-file.
With create CreateProcess you can't start lnk-files. And if you start the exe itself, you will perhaps miss some important settings like a special working directory or something like that.
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

Author Comment

by:alexandram
ID: 2612278
Madshi,

I considered that option but the problem was that I am using PostThreadMessage to close the application and therefore need the thread ID. From what I have experienced, PostThreadMessage with WM_QUIT is the best way to close applications. I can get the process handle with shellexecuteex but not the threadid. I am also using the threadid to bring windows back to the front. Is there a way to get the threadid from the process handle?
0
 
LVL 20

Expert Comment

by:Madshi
ID: 2612302
Not with documented means...   :-((
I do have code to get the processID from the process handle and to enumerate threads under all systems, but that's all undocumented and very ugly. I don't recommend using that.
So if you need the threadID I've another suggestion: Use the IShellLink interface to get all infos from the lnk-file. Then use CreateProcess with the parameters you've read.
0
 
LVL 3

Expert Comment

by:SamHobbs
ID: 2626427
I have not played around with CreateProcess a lot, but I have enough to say that probably WaitForInputIdle is a good idea and not likely to cause a problem.

The answer to not use CREATE_NEW_CONSOLE is probably the correct answer.

Do you know though what CreateProcess is returning when it does not work?
0
 
LVL 32

Expert Comment

by:jhance
ID: 2634338
alexandram,

What's up?  Six days without any response.....  Are you still alive?
0
 

Author Comment

by:alexandram
ID: 2634728
Sorry about the delay. The user who were having the problem haven't complained so maybe removing CREATE_NEW_CONSOLE fixed it. Thank you.
0

Featured Post

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question