In winapi, when creating buttons, the Access violation reading location exception occurs and in debugger writes that hWnd unused = ??? What does it mean?

Create buttons:

case WM_CREATE: // Π‘ΠΎΠΎΠ±Ρ‰Π΅Π½ΠΈΠ΅ ΠΏΡ€ΠΈΡ…ΠΎΠ΄ΠΈΡ‚ ΠΏΡ€ΠΈ создании ΠΎΠΊΠ½Π° easyLevel = CreateWindow("button", "Π›Π΅Π³ΠΊΠΈΠΉ", WS_CHILD, 420, 250, 150, 25, hWnd, (HMENU)1, ((LPCREATESTRUCT)lParam)->hInstance, NULL); middleLevel = CreateWindow("button", "Π‘Ρ€Π΅Π΄Π½ΠΈΠΉ", WS_CHILD, 420, 290, 150, 25, hWnd, (HMENU)2, ((LPCREATESTRUCT)lParam)->hInstance, NULL); hardLevel = CreateWindow("button", "Π‘Π»ΠΎΠΆΠ½Ρ‹ΠΉ", WS_CHILD, 420, 330, 150, 25, hWnd, (HMENU)3, ((LPCREATESTRUCT)lParam)->hInstance, NULL); buttonPlay = CreateWindow("button", "Π˜Π³Ρ€Π°Ρ‚ΡŒ!", WS_CHILD | WS_VISIBLE, 420, 250, 150, 25, hWnd, (HMENU)100, ((LPCREATESTRUCT)lParam)->hInstance, NULL); buttonExit = CreateWindow("button", "Π’Ρ‹Ρ…ΠΎΠ΄", WS_CHILD | WS_VISIBLE, 420, 300, 150, 25, hWnd, (HMENU)101, ((LPCREATESTRUCT)lParam)->hInstance, NULL); break; 

Generation of a field for a sapper game. If the button in the field is a bomb, then write "b" in it.

 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()); } } } 

Closed due to the fact that off-topic participants are Vladimir Martyanov , insolor , aleksandr barakin , Grundy , Saidolim 11 Apr '16 at 5:23 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • β€œQuestions asking for help with debugging (β€œ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - Vladimir Martyanov, insolor, aleksandr barakin, Grundy, Saidolim
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Minimum code to reproduce the problem is needed. Otherwise, you can guess for a long time ... - Vladimir Martyanov
  • It turns out that any object HWND can not read. - Vitali Skripka

1 answer 1

This means that the hWnd variable is in memory that cannot be read, and the unused field is the insides of the HWND type, you don’t need to know about them.