Solved

Using CreateProcess to run report

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Memory leak using records in a TVirtualStringTree 11 111
System restore point 4 91
FMX enumerated colours 2 84
Delphi: how to implement a User Shortcut mapper? 1 95
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…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

867 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

18 Experts available now in Live!

Get 1:1 Help Now