mosg mosg - 1 year ago 233
C Question

HowTo hide Console Window with WinAPI?

I'm trying to hide console window when my C application lauching with this simple WinAPI code:

#define CONSOLE_NAME "6FD66E14-FF0F-4B94-B8AF-AFE3D42DC399"

void hide_window(void)
// Ставим заголовок для консольного окна / Setting window caption

// Находим по заголовку Handle для окна / Searching Handle of the window
if (hWnd == 0)

// Скрываем консоль / Hidding console
ShowWindow(hWnd, SW_HIDE);

int _tmain(int argc, _TCHAR* argv[])

/* other code */

Everything works fine, if no antiviruses activated, but when Kaspersky is running and monitors the system, I can't get work the code above, because
hWnd == 0
is true and
= 183 error ("Cannot create a file when that file already exists.") lauched!

Question: What can I do? All that I need is to hide that console window.

Please, help me with this stuff.

Great thanks!

PS. Using Visual Studio 2010 (Visual C++)

Answer Source

Just call FreeConsole() get rid of it and AllocConsole() to create a new one.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download