Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to start console app minimized or with no console?

Posted on 1998-02-03
3
Medium Priority
?
409 Views
Last Modified: 2013-12-03
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
0
Comment
Question by:gunn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 7

Expert Comment

by:galkin
ID: 1410819
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
0
 

Author Comment

by:gunn
ID: 1410820
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_ReadTest.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);

}
0
 
LVL 11

Accepted Solution

by:
mikeblas earned 100 total points
ID: 1410821
You're incorrectly initializing nearly everything, and you don't know the difference between allocated memory and a pointer to allocated memory.

Here's some code that should be a lot closer to working than what you have written:

char *child_full_name = "D:\\DTM_Test\\DTM_ReadTest.exe";

// these are structures, not pointers

PROCESS_INFORMATION ProcessInfo;
STARTUPINFO InfoToPass;

/* lpInfoToPass->cb = 68;
      ???? how to get? */
// use sizeof()!

InfoToPass.cb = sizeof(InfoToPass);
InfoToPass.lpReserved = NULL;
InfoToPass.lpDesktop = NULL;
InfoToPass.lpTitle = NULL;
InfoToPass.dwFlags = STARTF_USESHOWWINDOW;
InfoToPass.cbReserved2 = 0;
InfoToPass.lpReserved2 = NULL;
InfoToPass.wShowWindow = SW_SHOWMINIMIZED;

printf("Testing Spawning Process\n");

// use ampersand on structures to get a pointer to
// the structures you intialized above

BOOL status1;
status1 = CreateProcess(child_full_name, "", NULL, NULL, FALSE,
   CREATE_NEW_CONSOLE, NULL, NULL, &InfoToPass, &ProcessInfo);

// errno is set by c runtime routnes, but CreateProcess() is a
// windows API. check the return code and GetLastError() instead
// of errno

if (status1)
{
   printf("it worked");
}
else
{
   printf("it failed.  Error code == %d", GetLastError());
}

.B ekiM




0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

705 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