   Creating a console in GUI mode? [SOLVED]
  NOTE: New question below.Is there a way to create a window (using 'CreateWindow') when a program is started as a console?I do know that some information is passed through the 'WinMain' function, but I am (obviously) starting with simply 'main'.Is there any way to get the HINSTANCE of a program by using function, instead of getting it by an argument? I can't find it, and I'm not sure whether that's the problem.Also, is there any way of getting a console window's HWND value?I've found AfxGetInstanceHandle, but that's for Visual C++, and I'm using Dev-C++ (MinGW). Does Windows have any function where you can get a program's HINSTANCE without knowing its name?Maybe I'm being too noobish...[Edited by - deadimp on June 3, 2006 12:02:46 PM]
  You want a graphical window to come from a console app? It may be possible, but its much more straight forward to create a console window from a graphical app.   ;  GetConsoleWindow() will give you the console's HWND. As for getting the HINSTANCE, there's always:HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(NULL);Ravyne is right, though. It's much nicer the other way around.   ;  Well, that's probably what I'm gonna want to do. I've tried many functions, including GetClassLong, GetWindowLong, etc, but to no avail. I found out that the handle to the module was fine, since DirectInput init'd okay, but my executable itself was not.I plugged in some code from the MSDN on 'GetLastError' and it told me that the "specified image file does not contain a resource section".Yeah, so now, I'm going to take y'all's suggestion.My only question now is, how do I create a console window?Thanks for the help!   ;Quote:Original post by deadimpMy only question now is, how do I create a console window?AllocConsole and FreeConsole.   ;  Well, now my only problem is now that I cannot get input nor show output from the console. It might be because of DirectInput... Checking.EDIT: I don't think it's DirectInput. I disabled it, and I got the same result.I'm using the C-standard IO library, printf, etc.   ;Quote:Original post by deadimpWell, now my only problem is now that I cannot get input nor show output from the console. It might be because of DirectInput... Checking.No, it has nothing to do with DirectInput. It has to do with the fact that the standard input and output handles for your allocated console are not the same as those created by the C I/O functions, or even C++ I/O streams.This article, Adding Console I/O to a Win32 GUI App provides a detailed explanation and source code on rectifying that problem for C++ I/O streams. It's not terribly difficult to switch to C I/O from there; actually, it should be fairly seamless, so long as you focus on the standard filehandles stdin, stdout and stderr.Good luck.   ;  Thanks! All's working fine and well, just have to reorganize my code.   