Hidden Console on Startup

I was looking for a solution to starting my console (not Windows) application without the console window briefly popping up before hiding - I posted about it in the past here:

http://www.cplusplus.com/forum/general/191480/

I failed to get this to work and reluctantly resorted to writing a little (Windows) helper app that sits next to my executable; here's the source:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <Windows.h>
#include <sstream>
using namespace std;

int main()
{
	string command("program.exe");

	STARTUPINFOA si = {0};
	PROCESS_INFORMATION pi = { 0 };

	si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
	si.wShowWindow = SW_HIDE;

	::CreateProcessA(command.c_str(), NULL, NULL, NULL, FALSE, 0, NULL,
	NULL, &si, &pi);
	

	return EXIT_SUCCESS;
}


With this I get an executable called hide.exe. I double click hide.exe and success - program.exe runs and no windows pop up.

Now the problem. I want hide.exe to automatically run on startup so I added a registry key to

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run

It doesn't work :'O

I can add a key for program.exe and it will run (visibly), or I can add a key for hide.exe that does nothing.

To reiterate, manually double clicking hide.exe successfully does what I'm trying to achieve, but Windows refuses to run it on startup.

I've tried different startup keys, different locations for the executables... does anyone know why this is happening and/or how to fix this?
Last edited on
Anyone have any experience with this issue? I'm starting to think Windows app is the only way..
closed account (E0p9LyTq)
Having main() as your app's start point, using standard C++ libraries, will always generate a console window before starting the GUI window, when run on Windows. That is just how Windows works.

To create a conformant Windows GUI app (no console window) requires using the Windows libraries and defining your app's start with WinMain(). You can still use the C/C++ libraries as needed. User interaction is done differently with a GUI app, vs. a console app.

The easiest way to do the above is use an IDE that let's you choose your project type so the IDE sets up all the "behind the scenes" settings for you.

I personally know of two IDEs that create properly set Win32 API projects Visual Studio and Dev-C++. I use both, though Dev-C++ is no longer being updated and was outdated with its last version.
Thanks for the reply, but I'm set on keeping the app console and pretty sure my shell commands w/ _popen will spawn visible windows even as a Windows app.

In my first post I mentioned that the little hide.exe my program generates works well - I'm just curious as to why Windows wont start it with this registry entry.
Topic archived. No new replies allowed.