visual studio 2022でウィンドウズデスクトップアプリケーションを作っているのですが、
「0x00007FFF4E59C8DA (ntdll.dll) で例外がスローされました (東方.exe 内): 0xC0000005: 場所 0xFFFFFFFFFFFFFFFF の読み取り中にアクセス違反が発生しました」
というエラーが出て困っています。
DWORD dwStyle = WS_OVERLAPPEDWINDOW;
の行で発生します。
c++、win32apiともに、あまり詳しくありません。
#include <windows.h>
//エントリーポイント
static LRESULT CALLBACK WndProc(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{
switch (uiMsg)
{
case WM_CLOSE:
{
DestroyWindow(hWnd);
return 0;
}
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
}
return DefWindowProc(hWnd, uiMsg, wParam, lParam);
}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdshow)
{
//ウィンドウの位置・サイズ
int x = 0;
int y = 0;
int width = 640;
int height = 480;
const TCHAR* pWindowName = TEXT("東方3D");
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = GetModuleHandle(NULL);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.lpszMenuName = NULL;
wcex.hIcon = LoadIcon(NULL, IDC_ARROW);
wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
RegisterClassExW(&wcex);
DWORD dwStyle = WS_OVERLAPPEDWINDOW;
RECT Rect;
Rect.left = 0;
Rect.top = 0;
Rect.right = width;
Rect.bottom = height;
AdjustWindowRect(&Rect, WS_OVERLAPPEDWINDOW, false);
width = Rect.right - Rect.left;
height = Rect.bottom - Rect.top;
HWND hWnd = CreateWindow(wcex.lpszClassName,
pWindowName,
dwStyle,
x,
y,
width,
height,
NULL,
NULL,
GetModuleHandle(NULL),
NULL
);
if (hWnd == NULL)
{
return false;
}
ShowWindow(hWnd, SW_SHOW);
UpdateWindow(hWnd);
MSG msg;
while (1)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message = WM_QUIT)
{
break;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return 0;
}