Click here to Skip to main content
15,888,287 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
the method i have mentioned below is opening the console for a split second but i want to execute the cpp compile exe file to be executed silently in te background without showing any console or command prompt
i have made empty project in visual c++
below is my code someone please tell me why its exe is showing cmd for a slit second i dont want to show cmd or console or anything and it shouldnt because its an empty project

What I have tried:

int main(int argc, char **argv)
{
HWND windowHandle = GetConsoleWindow();
ShowWindow(windowHandle, SW_HIDE);

}
Posted
Updated 27-Jul-23 4:23am
v3

If you created a Console app, when you launch your app by double-clicking it, the console is created and attached to your process before your code starts execution. There's no way to prevent the console window from showing up in that case.

Your only other option is to NOT create a console app and instead do a normal Windows application, like Griff said, and remove all the window code.
 
Share this answer
 
Comments
Member 12899279 5-Feb-20 10:31am    
is an empty project local application
Dave Kreskowiak 5-Feb-20 13:10pm    
That question makes no sense at all.
Member 12899279 5-Feb-20 22:39pm    
then why are you trying to answer if you can't help simply ignore
Dave Kreskowiak 6-Feb-20 0:22am    
I AM trying to answer. The problem is I said your "question" didn't make any sense. That means YOU have to do a better job of asking it, probably by defining what you mean by "local application".

Member 12899279 6-Feb-20 0:37am    
(an empty project for creating a local application)this is what i chose when i created the project and in linker subsytem it doesnt have windows or console it says(NotSet) sorry but i think i can't explain any more then this
Depend how you run it: the easiest way is to select a project type that doesn't have a console, or any other form of display, or to select a Windows project and remove all the form display code.
 
Share this answer
 
Comments
Member 12899279 5-Feb-20 10:30am    
its an empty project local application
Member 12899279 5-Feb-20 10:30am    
its an empty project local application
How do you execute the application? If you start it with CreateProcess from one of your programs there are arguments you can pass to CreateProcess that will prevent the console from being visible.

If you start it by double-clicking from the explorer then that method is not an option.
 
Share this answer
 
Are you looking for system() or perhaps _popen()? [NB there's wide char versions of those also as wsystem() and _wpopen()
e.g
C
#include <cstdlib>

int main()
{
    system("dir");
    return 0;
}

just runs a "dir" command without having to open a console.

_popen() does the same thing, but opens a pipe so that you can read or write to the command e.g.
C++
#include <cstdlib>
#include <iostream>

int main()
{
    FILE *cmdPipe = _popen("dir", "r");
    char buff[1024];
    while(fgets(buff, sizeof buff, cmdPipe) != NULL)
        std::cout << buff;
    fclose(cmdPipe);
    return 0;
}
 
Share this answer
 
v2
If you are using Visual Studio to compile your code, go to "Project properties" page. Then under "Configuration properties", go to "Linker", and then "System". Set "Subsystem" to "Not Set" or "Windows".
This way the compiler won't create a console window for you by default.
 
Share this answer
 
Comments
Member 12899279 27-Jul-23 10:43am    
You are few years late

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900