HELP: Launching a Windows Application from Delphi v2.0 
Author Message
 HELP: Launching a Windows Application from Delphi v2.0

Hi All,

I am trying to launch a 32-bit Windows-based application developed in
C/C++.  When I try execute it with WINEXEC, I get an error message.  (The
program reports an error in C2SYS)

How else can I launch the application?  Can it be launched in a window on
my form?  

I recall that the WinExec procedure is only for backwards compatibility.
Is this true?  Must I use CreateProcess?  If so, how do I use it?

Thanks in advance,
- Craig.



Tue, 16 Feb 1999 03:00:00 GMT  
 HELP: Launching a Windows Application from Delphi v2.0



Quote:
> Hi All,

> I am trying to launch a 32-bit Windows-based application developed in
> C/C++.  When I try execute it with WINEXEC, I get an error message.  (The
> program reports an error in C2SYS)

> How else can I launch the application?  Can it be launched in a window on
> my form?  

> I recall that the WinExec procedure is only for backwards compatibility.
> Is this true?  Must I use CreateProcess?  If so, how do I use it?

> Thanks in advance,
> - Craig.

Yes you should use CreateProcess.
Here is a small procedure that takes a command line as input, executes the
process (or program if you like) and wait until it terminates. You can
remove the call to WaitForSingleObject if you just want to launch the app
and let the calling app continue.

procedure CallExecutable(CommandLine: string);
var
   StartUpInfo: TStartUpInfo;
   ProcessInfo: TProcessInformation;
begin
        with StartUpInfo do
   begin
        lpReserved := NIL;
        lpDesktop := NIL;
        lpTitle := NIL;
        { ignored:
      dwX;
        dwY;
        dwXSize;
        dwYSize;
        dwXCountChars;
        dwYCountChars;
        dwFillAttribute; }
        dwFlags := 0;
        { ignored:
        WORD    wShowWindow;
        WORD    cbReserved2;
        LPBYTE  lpReserved2;
        HANDLE  hStdInput;
        HANDLE  hStdOutput;
        HANDLE  hStdError;
      }
                cb := sizeof(StartUpInfo); { size of structure }
   end;

        if not CreateProcess(
                NIL, { LPCTSTR  lpApplicationName,      // pointer to name of executable
module }
                PChar(CommandLine), { LPTSTR  lpCommandLine,    // pointer to command
line string }
        NIL, { LPSECURITY_ATTRIBUTES  lpProcessAttributes,      // pointer to
process security attributes }
                NIL, { LPSECURITY_ATTRIBUTES  lpThreadAttributes,       // pointer to thread
security attributes }
                False, { BOOL  bInheritHandles, // handle inheritance flag }
        0, { DWORD  dwCreationFlags,    // creation flags }
                NIL, { LPVOID  lpEnvironment,   // pointer to new environment block }
                NIL, { LPCTSTR  lpCurrentDirectory,     // pointer to current directory
name }
        StartUpInfo, { LPSTARTUPINFO  lpStartupInfo,    // pointer to STARTUPINFO

Quote:
}

                ProcessInfo { LPPROCESS_INFORMATION  lpProcessInformation       // pointer
to PROCESS_INFORMATION }
        )
        then
                raise Exception.Create(Format('Can not create process (%s), error-code:
%d', [CommandLine, GetLastError]))
        else
                WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
end;

--
Geir F Kiste

Mikromarc Library Automation software info can  be found on
http://www.mikromarc.no.



Sat, 20 Feb 1999 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Help: Launching ReportSmith run-time from Delphi application

2. I need HELP launching applications

3. how can I launch a windows program from my windows program

4. Connect Delphi v2 client/server with Oracle 7.2 on windows nt

5. BP hangs when launched from windows

6. How to launch windows' screensaver

7. How can I launch another Windows application from my Delphi program???

8. Help with Delphi V2 and Informix.

9. Help with Delphi V1, ODBC and MsAccess V2.0

10. Call Windows Applications from within Delphi

11. Delphi-Application for OS/2, Mac and Windows?

12. Windows Application Development in Pascal with DELPHI v1.0

 

 
Powered by phpBB® Forum Software