DirectX
Trying my first DX program. Just creating a window. I'm using VC++. Everything compiles but when I try to run the executable i get an error from windows:
The instruction at "0x77e12660" referenced memory at "-xcccccccc". The memory could not be "read".
Click on OK to terminate the program
Click on CANCEL to debug the program
************************************************
//Here's the source code
// Code taken from "Beginning DirectX9: Chapter 2
#include <windows.h>
HINSTANCE hInst;
HWND wndHandle;
bool initWindow( HINSTANCE hInstance);
LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
if (!initWindow( hInstance))
return false;
MSG msg;
ZeroMemory (&msg, sizeof(msg));
while (msg.message!=WM_QUIT )
{
while (GetMessage(&msg, wndHandle, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int) msg.wParam;
}
bool initWindow( HINSTANCE hInstance )
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = 0;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.hIconSm = 0;
RegisterClassEx(&wcex);
wndHandle = CreateWindow( "DirectXExample",
"DirectXExample",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
640,
480,
NULL,
NULL,
hInstance,
NULL);
if(!wndHandle)
return false;
ShowWindow(wndHandle, SW_SHOW);
UpdateWindow(wndHandle);
return true;
}
LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
You haven't initialised the lpszClassName member of the WNDCLASSEX structure - it needs to be set to the same class name that you use to create the window with in the CreteWindow() call.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement