Solved

Using CreateProcess to run report

Posted on 1998-03-17
4
212 Views
Last Modified: 2010-04-06
Hi

My application has to launch Paradox (any version) and run a report. I am fighting a losing battle to get CreateProcess to work. However, I still want to use this call. How do I get it to work? Assume I have the path to the correct version. Part 2: How can I disable my app from opening another version of this report; don't say, disable the button, because I still need to re-enable it, which brings us back to the same problem.
0
Comment
Question by:Edo082297
  • 2
4 Comments
 
LVL 4

Expert Comment

by:d003303
ID: 1360539
Why are you so bound on the CreateProcess commend ? Why don't you use OLE automation to solve this problem ?

Slash/d003303
0
 
LVL 1

Accepted Solution

by:
Greedy earned 100 total points
ID: 1360540
just make a call to this

function WinExecAndWait32(FileName:String; Visibility : integer):integer;
//  filename is the name of the executable and path if needed.
//  Visibility is how the window should be displayed.
//  1 = normal with focus
//  2 = minimized
//  3 = maximized
//  4 = normal/ no focus

var
  zAppName:array[0..512] of char;
  zCurDir:array[0..255] of char;
  WorkDir:String;
  StartupInfo:TStartupInfo;
  ProcessInfo:TProcessInformation;
begin
  StrPCopy(zAppName,FileName);
  GetDir(0,WorkDir);
  StrPCopy(zCurDir,WorkDir);
  FillChar(StartupInfo,Sizeof(StartupInfo),#0);
  StartupInfo.cb := Sizeof(StartupInfo);

  StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
  StartupInfo.wShowWindow := Visibility;
  if not CreateProcess(nil,
    zAppName,                      { pointer to command line string }
    nil,                           { pointer to process security attributes }
    nil,                           { pointer to thread security attributes }
    false,                         { handle inheritance flag }
    CREATE_NEW_CONSOLE or          { creation flags }
    NORMAL_PRIORITY_CLASS,
    nil,                           { pointer to new environment block }
    nil,                           { pointer to current directory name }
    StartupInfo,                   { pointer to STARTUPINFO }
    ProcessInfo) then Result := -1 { pointer to PROCESS_INF }

  else begin
    WaitforSingleObject(ProcessInfo.hProcess,INFINITE);
    GetExitCodeProcess(ProcessInfo.hProcess,Result);
  end;
end;

0
 
LVL 1

Author Comment

by:Edo082297
ID: 1360541
I am using CreateProcess for this because I need to instantiate a separate thread for the WaitForSingleObjectEx call. I do not want the user playing with the 'main' application while the Paradox portion is going, d003303.


0
 
LVL 1

Author Comment

by:Edo082297
ID: 1360542
I am using CreateProcess for this because I need to instantiate a separate thread for the WaitForSingleObjectEx call. I do not want the user playing with the 'main' application while the Paradox portion is going, d003303.

I grade Greedy's answer as good, only because I got it to work with less code. Is this better? Perhaps not. I used GetStartupInfo instead of intializing the STARTUP_INFO structure myself (is this necessary?), and because I am not sure of the role of zCurDir and WorkDir. Also, why is the WaitForSingleObject call in an else portion? Isn't this counter-intuitive, or is this the way it's done? While you're at it, greedy, could I have used OLE automation to do this? Would I want to?


0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

773 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