Handmade Hero » Forums » Day 002 Error with CreateWindowEx()
tudrare555
Tudor
7 posts
#13740 Day 002 Error with CreateWindowEx()
1 month, 1 week ago

I've started this tutorial 2 days ago, but I ended up having this error at day 002:
"Exception thrown at 0x0000000000000000 in win32_handmade.exe: 0xC0000005: Access violation executing location 0x0000000000000000."

My code looks like this:
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
#include <windows.h>

LRESULT CALLBACK 
WindowProc( HWND   Window,
            UINT   Message,
            WPARAM wParam,
            LPARAM lParam
)
{
  LRESULT Result = 0;

  switch(Message)
  {
    case WM_CREATE:
    {
      OutputDebugStringA("WM_CREATE\n");
    }break;

    case WM_SIZE:
    {
      OutputDebugStringA("WM_SIZE\n");
    }break;

    case WM_DESTROY:
    {
      OutputDebugStringA("WM_DESTROY\n");
    }break;

    case WM_CLOSE:
    {
      OutputDebugStringA("WM_CLOSe\n");
    }break;

    case WM_ACTIVATEAPP:
    {
      OutputDebugStringA("WM_ACTIVATEAPP\n");
    }break;

    default:
    {
      OutputDebugStringA("default\n");
      Result = DefWindowProc(Window, Message, wParam, lParam);
    }break;
  }
  return Result;
}

int CALLBACK 
WinMain(HINSTANCE Instance,
        HINSTANCE hPrevInstance,
        LPSTR     lpCmdLine,
        int       nCmdShow
)
{
  WNDCLASS WindowClass = {};

  //TODO: Check if CS_HREDRAW CS_OWNDC CS_VREDRAW still matters
  WindowClass.style = CS_OWNDC|CS_HREDRAW|CS_VREDRAW;
  WindowClass.lpfnWndProc;
  WindowClass.hInstance = Instance;
  //WindowClass.hIcon;
  WindowClass.lpszClassName = "HandmadeHeroWindowClass";

  if(RegisterClass(&WindowClass))
  {
      HWND WindowHandle =
            CreateWindowEx( //EROR HAPPENS HERE
                0,
                WindowClass.lpszClassName,
                "Handmade Hero",
                WS_OVERLAPPEDWINDOW|WS_VISIBLE,
                CW_USEDEFAULT,
                CW_USEDEFAULT,
                CW_USEDEFAULT,
                CW_USEDEFAULT,
                0,
                0,
                Instance,
                0);
      if(WindowHandle)
      {
        for(;;)
        {
          MSG Message;
          BOOL MessageResult = GetMessage(&Message, 0, 0, 0);
          if(MessageResult > 0)
          {
            TranslateMessage(&Message);
            DispatchMessage(&Message);
          }
          else
          {
            break;
          }
        }
      }
      else
      {
        //TODO: Logging
      }
  }
  else
  {
    //TODO: Logging
  }

	return 0;
}


Please help me!
Croepha
David Butler
69 posts
1 project

I love pretty much anything technical, whether it be programming, networking, hacking or electronics.

#13742 Day 002 Error with CreateWindowEx()
1 month, 1 week ago

I don't have windows booted up to confirm, but I suspect that you need
1
WindowClass.lpfnWndProc = WindowProc;
Also, please include a copy of your backtrace for runtime errors.

404 Signature not found
tudrare555
Tudor
7 posts
#13743 Day 002 Error with CreateWindowEx()
1 month, 1 week ago

Thanks! It worked!