Solved

Using CreateProcess to run report

Posted on 1998-03-17
4
210 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now