Original Post
Even with copying from the SDK I''m cursed ... I''ve been trying for two days or so now to get direct x 8 setup, and still haven''t completely grasped it...
Anyone know what this means? Unhandled exception at 0x004122f7 in Win32APP.exe: 0xC0000005: Access violation reading location 0x00000000.

#include <windows.h>
#include "d3d8.h" // Direct 3D
#include "d3dx8.h" // D3DX
// Other Dependencies
// Application Dimensions, Type, Class, and WindowName
#define WNDWIDTH 400
#define WNDHEIGHT 400
#define WNDTYPE WS_OVERLAPPEDWINDOW
const char g_szClass[] = "GameClass";
const char g_szCaption[] = "GameClassTitle";
// Window Creation
HWND hWnd;
WNDCLASSEX wcex;
// DirectX
IDirect3D8* g_pD3D; // Direct3D Object
D3DDISPLAYMODE d3ddm; // Direct3D Display Mode
IDirect3DDevice8* g_pd3dDevice; // Device Interface
D3DPRESENT_PARAMETERS d3dpp;
// Function Prototypes
LRESULT CALLBACK WindowProc(HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, // Instance handle of the application
HINSTANCE hPrevInstance, // Unused
LPSTR lpCmdLine, // Command line options (if any)
int nCmdShow); // Show window flag
bool RegisterWindowClasses(HINSTANCE hInst, HWND& hWnd, WNDCLASSEX& wcex);
bool UnregisterWindowClasses(HINSTANCE hInst);
bool DoInit();
bool DoShutdown();
bool DoPreFrame();
bool DoFrame();
bool DoPostFrame();
void Render();
// Function Declarations
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
// Register Window Classes
if(RegisterWindowClasses(hInstance, hWnd, wcex) == false)
return false;
// Creates Direct3D Object
if( NULL == ( g_pD3D = Direct3DCreate8( D3D_SDK_VERSION ) ) )
return E_FAIL;
// Sets Direct3D Display Mode
if( FAILED( g_pD3D->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &d3ddm ) ) )
return E_FAIL;
ZeroMemory( &d3dpp, sizeof(d3dpp) );
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = d3ddm.Format;
// Creates The direct3D device
if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &g_pd3dDevice ) ) )
// Initilize Program Variables
if(DoInit == false)
return false;
MSG msg;
while( GetMessage( &msg, NULL, 0, 0 ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
if(DoShutdown == false)
{
// Shutdown Error
}
// Destroy Window Class
UnregisterWindowClasses(hInstance);
return 0;
}
LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_DESTROY:
PostQuitMessage(0); // Tell windows to close application
break;
case WM_PAINT:
Render();
ValidateRect( hWnd, NULL );
return 0;
// Pass remaining messages to message handler
default:
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
return 0;
}
bool RegisterWindowClasses(HINSTANCE hInst, HWND& hWnd, WNDCLASSEX& wcex)
{
// Register the window class.
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_CLASSDC;
wcex.lpfnWndProc = WindowProc;
wcex.cbClsExtra = 0L;
wcex.cbWndExtra = 0L;
wcex.hInstance = GetModuleHandle(NULL);
wcex.hIcon = NULL;
wcex.hCursor = NULL;
wcex.hbrBackground = NULL;
wcex.lpszMenuName = NULL;
wcex.lpszClassName = g_szClass;
wcex.hIconSm = NULL;
if(!RegisterClassEx( &wcex ))
return false;
// Create the application''s window.
hWnd = CreateWindow( g_szClass, g_szCaption,
WNDTYPE, 0, 0, WNDWIDTH, WNDHEIGHT,
GetDesktopWindow(), NULL, wcex.hInstance, NULL );
if(hWnd == NULL)
return false;
ShowWindow(hWnd, SW_SHOWNORMAL);
UpdateWindow(hWnd);
return true;
}
bool UnregisterWindowClasses(HINSTANCE hInst)
{
UnregisterClass(g_szClass, hInst);
return true;
}
bool DoInit()
{
return true;
}
bool DoShutdown()
{
return true;
}
bool DoFrame()
{
return false;
}
void Render()
{
g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0f, 0 );
}
