Go Back   Wiki NewForum | Latest Entertainment News > Career Forum & Tips > Tech Forum & Tutorial > Oracle Database, SQL, Application, Programming


Calling CreateProcess() the easy way


Reply
Views: 1229  
Thread Tools Rate Thread
  #1  
Old 08-11-2010, 02:47 PM
bholas bholas is offline
Award Winner
 
Join Date: Apr 2010
Posts: 4,977
Default Calling CreateProcess() the easy way

If you look up the CreateProcess() function in Win32 help, you'll notice that there are more than three dozen parameters that you can optionally setup before calling it. The good news is that you have to setup only a small number of those parameters to make a simple CreateProcess() call as demonstrated in the following function:

function CreateProcessSimple(
***ecutableFilePath : string )
: string;
var
pi: TProcessInformation;
si: TStartupInfo;
begin
FillMemory( @si, sizeof( si ), 0 );
si.cb := sizeof( si );

CreateProcess(
Nil,

// path to the executable file:
PChar( ***ecutableFilePath ),

Nil, Nil, False,
NORMAL_PRIORITY_CLASS, Nil, Nil,
si, pi );

// "after calling code" such as
// the code to wait until the
// process is done should go here

CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
end;
Now, all you have to do is call CreateProcessSimple(), let's say to run Windows' Notepad:


CreateProcessSimple( 'notepad' );

Reply With Quote
Reply

Tags
programming tips

New topics in Oracle Database, SQL, Application, Programming





Powered by vBulletin® Version 3.8.10
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
WikiNewForum)