HWND - Unable to read memory

So I'm working with DirectX 11 and for some reason the debugger is telling me that the memory of my HWND is unreadable. I've even used the Win32 template from Visual Studio and it's still unable to read the memory. This is problematic because my DirectX class constructor takes a HWND as a parameter to set up the swapchain and the CreateDeviceAndSwapChain function fails because of that.

Here's my code to create the window:
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
#pragma once

#include <Windows.h>

#include "D3D11App.h"

class WindowsObject
{
public:
	WindowsObject();

	void MessageProcedure();

private:
	void InitializeWindow(int displayResWidth, int displayResHeight, bool displayWindowed);

private:
	HWND m_hWnd;
	const HINSTANCE m_hInstance;
	const LPCWSTR m_windowClassName;
	int m_windowPosX;
	int m_windowPosY;
};

LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);


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
#include "WindowsObject.h"

WindowsObject::WindowsObject()
:
m_hInstance(GetModuleHandle(NULL)),
m_windowClassName(L"DirectX11Engine")
{
	InitializeWindow(800, 600, true);
}

void WindowsObject::InitializeWindow(int displayResWidth, int displayResHeight, bool displayWindowed)
{
	WNDCLASSEX wc;

	ZeroMemory(&wc, sizeof(wc));
	wc.cbClsExtra = NULL;
	wc.cbSize = sizeof(WNDCLASSEX);
	wc.cbWndExtra = NULL;
	wc.hbrBackground = (HBRUSH)(COLOR_WINDOW);
	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
	wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
	wc.hInstance = m_hInstance;
	wc.lpfnWndProc = WndProc;
	wc.lpszClassName = m_windowClassName;
	wc.lpszMenuName = NULL;
	wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;

	RegisterClassEx(&wc);

	if(displayWindowed)
	{
		m_windowPosX = (GetSystemMetrics(SM_CXSCREEN) - displayResWidth) / 2;
		m_windowPosY = (GetSystemMetrics(SM_CYSCREEN) - displayResHeight) / 2;

		m_hWnd = CreateWindowEx(NULL, m_windowClassName, L"DirectX 11 App", WS_OVERLAPPEDWINDOW,
			m_windowPosX, m_windowPosY, displayResWidth, displayResHeight, NULL, NULL, m_hInstance, NULL);
	}

	ShowWindow(m_hWnd, SW_SHOW);
	UpdateWindow(m_hWnd);
}

void WindowsObject::MessageProcedure()
{
	D3D11App D3DApp(m_hWnd);

	MSG msg;

	ZeroMemory(&msg, sizeof(msg));
	while(msg.message != WM_QUIT)
	{
		if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		else
		{

		}
	}
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch(msg)
	{
		case WM_DESTROY:
			PostQuitMessage(0);
			break;
	}

	return DefWindowProc(hWnd, msg, wParam, lParam);
}


EDIT: Fixed the problem. I forgot to set the buffer format. And I thought the HWND was causing the problem but I did some research and it turns out that's the normal value for it.
Last edited on
Topic archived. No new replies allowed.