Don't know CoderJames. I don't work with networked stuff much, so you likely know more about this than I. I'm stretching a bit here, but I suppose, conceptually, a console process is logically distinct from a GUI process. I know a process can be started without a console, so I wouldn't expect in such a process, if a call was made to obtain a HWND, that one could be assigned to the variable.
But in typical Windows desktop apps such as the OP is speaking of running locally, when the console is created if that type of app was specified in the project setup, Windows internally executes some kind of CreateWindow() call which generates a HWND which can be obtained, as I said. Also, many other Windows Api functions usually associated with GUI processes can be executed against a console window. For one example, older compilers won't have that GetConsoleWindow() function I discussed above. However, in cases where it is missing, FindWindow() can be called to obtain it instead. And of course, FindWindow() is about as GUI as you can get. And here is a little routine I put together to prevent the user from closing a console window through clicking the [x] in the Title Bar...
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
void DisableCloseButton()
{
char szBuffer[256];
if(GetConsoleTitle(szBuffer,256))
{
HWND hConsole=FindWindow(NULL,szBuffer);
if(hConsole)
{
HMENU hSysMenu=GetSystemMenu(hConsole,0);
DeleteMenu(hSysMenu,6,MF_BYPOSITION);
}
}
}
|
Many other GUI Api functions also can be used against consoles, even TextOut(). With a HWND as obtained above, one can obtain a Handle to a Device Context, and use that function. Now doing that likely won't insert the text printed to the console's underlying screen buffer, but it more or less proves my point.
So in a practical sense, a console is that alternate byte you spoke of in the PE Header, some kind of internal CreateWindow() call to provide the visible console, and the underlying plumbing to provide the Api console functions, e.g., ReadConsoleInput(), WriteConsole(), Set ConsoleMode(), etc.