gunn
asked on
How to start console app minimized or with no console?
I have a Windows GUI program in which I spawn another process that runs in a DOS shell (using the _spawnl ) command.
I was wondering how to get this process to either start with the console minimized, And/OR:
with the console not appearing at all? It really doesn't need to be seen, only for debugging messages that are sometimes printed out.
Thanks,
Tom
I was wondering how to get this process to either start with the console minimized, And/OR:
with the console not appearing at all? It really doesn't need to be seen, only for debugging messages that are sometimes printed out.
Thanks,
Tom
Use CreateProcess instead. wShowWindow member of STARTUPINFO structure passed to CreateProcess contaons information of main process window. Set it to SW_HIDE or SW_SHOWMINIMIZED. Be sure to specify STARTF_USESHOWWINDOW in dwFlags filed of STARTUPINFO
ASKER
I've tried to use this for awhile now and I can't get it to work, no matter what. Heres the sample code I wrote to use the CreateProcess function. What am I doing wrong? Grrrrrr
Its hanging up on CreateProcess for a couple of seconds, and then it gives me a "First-chance exception in TestSpawn.exe (KERNEL32.DLL) 0xC000005 : Access Violation" errors.
I've also had it hang up on the
lpInfoToPass->cb = 68;
because sometimes lpInfoToPass address is 0x00000 at this point? But then sometimes its ok too.....
/*---------------------*/
#include <windows.h>
#include <process.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
void main()
{
char err_string[256] = "Error in Spawning: ";
BOOL status1;
extern int errno;
/* A small console app to execute */
char *child_full_name = "D:\\DTM_Test\\DTM_ReadTes t.exe";
LPPROCESS_INFORMATION lpProcessInfo;
LPSTARTUPINFO lpInfoToPass;
lpInfoToPass->cb = 68; /* ???? how to get? */
lpInfoToPass->lpReserved = NULL;
lpInfoToPass->lpDesktop = NULL;
lpInfoToPass->lpTitle = NULL;
lpInfoToPass->dwFlags = STARTF_USESHOWWINDOW;
lpInfoToPass->cbReserved2 = 0;
lpInfoToPass->lpReserved2 = NULL;
lpInfoToPass->wShowWindow = SW_SHOWMINIMIZED;
printf("Testing Spawning Process\n");
/*
status1 = _spawnl( _P_NOWAIT, child_full_name,
child_full_name, NULL );
*/
status1 = CreateProcess( child_full_name, child_full_name, NULL, NULL, FALSE,
CREATE_NEW_CONSOLE, 0, 0,
lpInfoToPass, lpProcessInfo );
/* print out the error message if status = -1 */
if( errno != 0 )
perror( err_string );
exit(0);
}
Its hanging up on CreateProcess for a couple of seconds, and then it gives me a "First-chance exception in TestSpawn.exe (KERNEL32.DLL) 0xC000005 : Access Violation" errors.
I've also had it hang up on the
lpInfoToPass->cb = 68;
because sometimes lpInfoToPass address is 0x00000 at this point? But then sometimes its ok too.....
/*---------------------*/
#include <windows.h>
#include <process.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
void main()
{
char err_string[256] = "Error in Spawning: ";
BOOL status1;
extern int errno;
/* A small console app to execute */
char *child_full_name = "D:\\DTM_Test\\DTM_ReadTes
LPPROCESS_INFORMATION lpProcessInfo;
LPSTARTUPINFO lpInfoToPass;
lpInfoToPass->cb = 68; /* ???? how to get? */
lpInfoToPass->lpReserved = NULL;
lpInfoToPass->lpDesktop = NULL;
lpInfoToPass->lpTitle = NULL;
lpInfoToPass->dwFlags = STARTF_USESHOWWINDOW;
lpInfoToPass->cbReserved2 = 0;
lpInfoToPass->lpReserved2 = NULL;
lpInfoToPass->wShowWindow = SW_SHOWMINIMIZED;
printf("Testing Spawning Process\n");
/*
status1 = _spawnl( _P_NOWAIT, child_full_name,
child_full_name, NULL );
*/
status1 = CreateProcess( child_full_name, child_full_name, NULL, NULL, FALSE,
CREATE_NEW_CONSOLE, 0, 0,
lpInfoToPass, lpProcessInfo );
/* print out the error message if status = -1 */
if( errno != 0 )
perror( err_string );
exit(0);
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.