I have a game sapper. When you press the select button, the difficulty level starts like this

if (LOWORD(wParam) == 1) { ShowWindow(easyLevel, SW_HIDE); ShowWindow(middleLevel, SW_HIDE); ShowWindow(hardLevel, SW_HIDE); Field myField = Field(10, 10); for (int i = 0; i < myField.getSizeX(); i++) { for (int j = 0; j < myField.getSizeY(); j++) { if (myField.getField()[i][j].isBomb()) { myField.getField()[i][j].setButton(CreateWindow("button", "b", WS_CHILD | WS_VISIBLE, 370 + j * 25, 250 + i * 25, 25, 25, hWnd, (HMENU)(i + j + 1), ((LPCREATESTRUCT)lParam)->hInstance, NULL)); } else { myField.getField()[i][j].setButton(CreateWindow("button", "", WS_CHILD | WS_VISIBLE, 370 + j * 25, 250 + i * 25, 25, 25, hWnd, (HMENU)(i + j + 1), ((LPCREATESTRUCT)lParam)->hInstance, NULL)); } UpdateWindow(myField.getField()[i][j].getButton()); } } } 

This code displays the field on the screen. But when you call getField, the Access violation reading location exception occurs.

  • one
    And what is the problem expressed? - Vladimir Martyanov
  • one
    You never know what the debugger writes. The question is, what is wrong? - VladD
  • And what makes you think that your departure "when calling getField" has something to do with HWND ? - AnT pm
  • already realized that the error occurs when calling CreateWindow, but I don’t understand why - Vitali Skripka

1 answer 1

HWND can be defined as typedef void* HWND , or it can be a structure in which there is a pointer.

At the same time, the HWND values ​​are small numbers, and naturally the debugger cannot read the memory from this pointer, because in fact, the HWND is not a pointer and it does not point anywhere.