CreateWindow failure

This is a discussion on CreateWindow failure within the Windows Programming forums, part of the Platform Specific Boards category; Hi there, I'm in the starting process of making my first game engine, and I've got the code to make ...

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    30

    CreateWindow failure

    Hi there, I'm in the starting process of making my first game engine, and I've got the code to make a basic window, but for some reason, I cant seem to get my CreateWindow function to work. It keeps failing. I added in a bit of Error handling code, and this is the reason I get:

    "CreateWindow() failed with error 8: Not enough storage is available to process this command."

    What are the reasons for this error message and failure of CreateWindow? The only one I am aware of, is there are not enough handles available so it fails, but I've excluded that idea, because I've rebooted my computer numerous times to refresh windows, but to no avail. Here is the code where I try to set up and create the window:

    Code:
    Engine::Engine(EngineConfig *config)
    {
    	m_Loaded = false; 
    
    	m_pConfig = new EngineConfig;
    	if (config)
    		memcpy(m_pConfig, config, sizeof(EngineConfig));
    
    	g_pEngine = this;
    
    	WNDCLASSEX wc;
    	wc.cbSize        = sizeof( WNDCLASSEX );
    	wc.style         = CS_CLASSDC;
    	wc.lpfnWndProc   = WndProc;
    	wc.cbClsExtra    = 0;
    	wc.cbWndExtra    = 0;
    	wc.hInstance     = m_pConfig->hInstance;
    	wc.hIcon         = LoadIcon( NULL, IDI_APPLICATION );
    	wc.hCursor       = LoadCursor( NULL, IDC_ARROW );
    	wc.hbrBackground = NULL;
    	wc.lpszMenuName  = NULL;
    	wc.lpszClassName = "WindowClass";
    	wc.hIconSm       = LoadIcon( NULL, IDI_APPLICATION );
    
    	// Check for class registration failure
    	if (FAILED(RegisterClassEx(&wc)))
    	{
    		ShowError("RegisterClassEx()");
    		m_Loaded = false;
    		return;
    	}
    
    	CoInitializeEx(0, COINIT_MULTITHREADED);
    
    
    	m_Window = CreateWindow("WindowClass", m_pConfig->name, WS_OVERLAPPED, 
    							0, 0, 800, 600, NULL, NULL, 
    							0, NULL );
    	// Check for CreateWindow Failure
    	if (!m_Window)
    	{
    		ShowError("CreateWindow()");
    		m_Loaded = false;
    		return;
    	}
    
    	// We're loaded and ready to go!
    	m_Loaded = true;
    }
    I would appreciate any help

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    You don't seem to have specified an instance handle when creating your window. Also, check to make sure that m_pConfig->name is properly initialised - try replacing it with an explicit string value (or zero) in your call to CreateWindow.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Registered User
    Join Date
    Apr 2005
    Posts
    30
    The MSDN said that on NT systems, the instance handle isnt used. I've tried both of those, and I still get the same error.

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    I've never noticed that before (about the instance) but then I rarely, if ever, use CreateWindow (msdn says nothing about that under the description of CreateWindowEx); but it's interesting to know nonetheless.

    It still looks suspiciously like a problem with your engine class - try replacing
    Code:
    wc.hInstance     = m_pConfig->hInstance;
    with
    Code:
    wc.hInstance     = GetModuleHandle(0);
    making sure that you also replace other 'm_pConfig' member variables with explicit values in the rest of your window registration code.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  5. #5
    Registered User
    Join Date
    Apr 2005
    Posts
    30
    No hmm, I still seem to get the same error.

    I'm going to search through the MSDN about the error and see what I can find.

    [EDIT]

    ok, I found this on the MSDN:

    Error Message:

    Not enough storage is available to process this command.
    User Action:

    Do one of the following, then retry the command: (1) reduce the number of running programs; (2) remove unwanted files from the disk the paging file is on and restart the system; (3) check the paging file disk for an I/O error; or (4) install additional memory in your system.
    Although, no other programs give me any errors or problems when I run them, just this one. I'm really confused
    Last edited by TheDan; 07-08-2005 at 07:44 AM.

  6. #6
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Do you process any messages that are issued during system processing of CreateWindow, such as WM_NCREATE or WM_CREATE? Errors in these may cause window creation to fail.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  7. #7
    Registered User
    Join Date
    Apr 2005
    Posts
    30
    Aha, thank you, I had forgotten about checking my WNDPROC.

    I had forgotten to add in DefWindowProc() as the default. Whoops

    Thank you for your help, it works now

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File I/O Assertion Failure in VS2008
    By clegs in forum C Programming
    Replies: 5
    Last Post: 12-25-2008, 04:47 AM
  2. Integer Emulation
    By Elysia in forum C++ Programming
    Replies: 31
    Last Post: 03-18-2008, 02:03 PM
  3. getting fed up with CreateWindow
    By ... in forum Windows Programming
    Replies: 2
    Last Post: 10-01-2003, 04:42 PM
  4. Am i a Failure?
    By Failure!!! in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 05-28-2003, 12:50 PM
  5. Assertion failure while creating window
    By roktsyntst in forum Windows Programming
    Replies: 0
    Last Post: 02-10-2003, 08:18 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21