Everytime you create an object (g_pDirect3D, g_pDirect3D_Device) you have to check if it has been created or if an error has occured.
add this
Code:
g_pDirect3D = Direct3DCreate9(D3D_SDK_VERSION);
if (g_pDirect3D == NULL)
{
MessageBox(hMainWnd, L"Error creating Direct3D object!", L"Error", MB_ICONERROR);
return -1;
}
and this
Code:
g_pDirect3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hMainWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING, &PresentParams, &g_pDirect3D_Device);
if (g_pDirect3D_Device == NULL)
{
MessageBox(hMainWnd, L"Error creating Direct3DDevice object!", L"Error", MB_ICONERROR);
return -1;
}
also leave
Code:
g_pDirect3D_Device->Release();
g_pDirect3D->Release();
from the WndProc function and insert them in WinMain, just above the instruction
return 0;
then insert this at the first line of the source file:
Code:
#pragma comment(lib, "d3d9.lib")