How to make a console program doesn't have console window - c++

I'm writing a console program.
The program doesn't print anything.
So, it doesn't need to a console window.
I tried to call FreeConsole() function at program starting point.
When I execute the program from windows explorer, a console window appears and then disappears.
But I wish the console window never appears.
How can I do that?
Thanks in advance.

If you are using Visual Studio .Net then create a normal console application and change the output type to Windows application.

Use WinMain instead of main as your program's entry point: WinMain at MSDN

Related

How to hide console window while opening hidden COM object using C++?

I am new to C++ so please be gentle. So i created a small C++ script which will be a part of a larger program. It creates an invisible window and navigates to home. While that part is done, it always creates a console window when it finishes execution and then in less than a second it vanishes. What do i need to change in order to make the program work in a way that the console window won't open ?
Instead of compiling as a console application, compile as a windows desktop project. Then convert main to be WinMain

How to create a windows application in C++ showing just a TaskDialog

I need to create a windows application in C++ and it has to show just a TaskDialog (see http://msdn.microsoft.com/en-us/library/windows/desktop/bb760540(v=vs.85).aspx ). The TaskDialog should show a text passed as parameter to the command line.
I can make a "Win32 Console Application" and call TaskDialog but then I will see the black windows of the console.
I can make a "Windows Application" and just calling TaskDialog inside WinMain, is there any problem with this solution?
Any other idea?
I can make a "Windows Application" and just calling TaskDialog inside WinMain, is there any problem with this solution?
That is the way to implement such an app. There is no problem with it all. Of course you don't create a window explicitly in your code and you don't run a message loop. Just call TaskDialog.
The main point is that you don't want a console app because, as you have discovered, a console window is shown by default. There are two main subsystems, the console subsystem and the GUI subsystem. The latter is somewhat confusingly named. You are not compelled to show GUI in a GUI subsystem app. It's up to you whether or not you choose to do so. Really the choice comes down to whether or not you want a console. So the subsystems could be better named as console and non-console!
You have to create a empty windows application.
The entry point of a windows application is calles WinMain and looks like this:
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
//Place your code here
}
This means your solution is correct. You just have to make sure that your application uses version 6 of Comctl32.dll. Otherwise TaskDialog will fail.

Console output window in DLL

I am trying to redirect the output from my DLL to an external console window for easy debugging.
I have been told about AllocConsole but I am not able to reproduce it, i.e. the console window does not appear.
My current environment is Visual Studio 2005.
I tried the following example which is gotten off the Internet,
AllocConsole();
HANDLE han = GetStdHandle(STD_OUTPUT_HANDLE);
WriteConsole(han,"hello",6,new DWORD,0);
yet nothing happens. Can someone point me in the right direction if creating a console window via DLL is possible in the first place.
Thanks in advance!
The proper way to output debug strings is via OutputDebugString(), with an appropriate debugging tool listening for output strings.
Once loaded, there is nothing special about DLLs, so there is no way that allocating consoles would be any different for a DLL than for the EXE that originally loaded it.
Having said that, a process can be associated with only one console at a time, so if there is already a console attached to the process, then allocating a new one is not going to do anything (I assume you're checking the return value of AllocConsole? What does it return? What does GetLastError return?)
There are some other possibilities. For example, if your DLL is loaded into a service, then the service will (likely) be running under a different window station to the currently logged-in user so if you create a console window, you won't be able to see it.

Can you create a start-up window in console program?

I want to a create dialog box like window before displaying the console window. I haven't actually tried anything yet but was just wondering if it can be displayed as a start-up window.
If you compile your win32 application as a console app, the console window will appear before you get a chance to do anything else.
To get around this, you need to use a windows application - this won't display a console window at all by default. Some time after startup you can then call AllocConsole to create a console window.
I'm not sure, but if it's a windowed application already, it might be worth making your own console window to redirect standard IO. It'll certainly look nicer. If you want the exact behavior of the regular console, such as the same copy/paste, you'd have to reimplement it.

C/C++ Console Windows WIN32

I know how to "hide" them. I know about FreeConsole(); and then finding the handle and changing it's attributes. However with these methods the window still pops up for a second than goes away. How can I stop it from showing up completely?
Have you considered creating a windows application (with windows subsystem) instead of a console application? That should hide the console window all together.
Try looking at WinMain
I believe you need to be a GUI application to not have the console displayed. Check out /SUBSYSTEM:WINDOWS