getting straight to the point, my program compiles fine.. it shows 0 errors and 0 warnings... but when i run my program, it just crashes.. u know the usual dialog box with buttons like send dont send and debug.. .. here's the code..
// include the basic windows header file
#include <windows.h>
#include <windowsx.h>
#include <d3d9.h>
//adding d3d9.lib
#pragma comment(lib,"d3d9.lib")
//pointer declaration for interface and device
LPDIRECT3D9 d3d;//interface
LPDIRECT3DDEVICE9 d3ddev;//device
void initD3D(HWND hWnd);
void render_frame(void);
void cleanD3D(void);
// the WindowProc function prototype
LRESULT CALLBACK WindowProc(HWND hWnd,
UINT message,
WPARAM wParam,
LPARAM lParam);
// the entry point for any Windows program
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// the handle for the window, filled by a function
HWND hWnd;
// this struct holds information for the window class
WNDCLASSEX wc;
// clear out the window class for use
ZeroMemory(&wc, sizeof(WNDCLASSEX));
// fill in the struct with the needed information
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)WindowProc;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.lpszClassName = "WindowClass1";
// register the window class
RegisterClassEx(&wc);
// create the window and use the result as the handle
hWnd = CreateWindowEx(NULL,
"WindowClass1", // name of the window class
"Our First D3D Program", // title of the window
WS_OVERLAPPEDWINDOW, // window style
300, // x-position of the window
300, // y-position of the window
640, // width of the window
480, // height of the window
NULL, // we have no parent window, NULL
NULL, // we aren't using menus, NULL
hInstance, // application handle
NULL); // used with multiple windows, NULL
// display the window on the screen
ShowWindow(hWnd, nCmdShow);
initD3D(hWnd);
// enter the main loop:
// this struct holds Windows event messages
MSG msg;
// wait for the next message in the queue, store the result in 'msg'
/*while(GetMessage(&msg, NULL, 0, 0))
{
// translate keystroke messages into the right format
TranslateMessage(&msg);
// send the message to the WindowProc function
DispatchMessage(&msg);
}*/
while (TRUE)
{
DWORD start_point= GetTickCount();
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
if (msg.message==WM_QUIT)
{
break;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
render_frame();
while((GetTickCount()-start_point<25));
//else run the game codes here....
}
// return this part of the WM_QUIT message to Windows
cleanD3D();
return msg.wParam;
}
// this is the main message handler for the program
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
// sort through and find what code to run for the message given
switch(message)
{
// this message is read when the window is closed
case WM_DESTROY:
{
// close the application entirely
PostQuitMessage(0);
return 0;
} break;
}
// Handle any messages the switch statement didn't
return DefWindowProc (hWnd, message, wParam, lParam);
}
//function definition for all the three functions
//the 1st function (initD3D) initializes direct 3D
void initD3D(HWND hWnd)
{
d3d=Direct3DCreate9(D3D_SDK_VERSION);
D3DPRESENT_PARAMETERS d3dpp;
d3dpp.Windowed=FALSE;
d3dpp.SwapEffect=D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow=hWnd;
d3d->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWnd,D3DCREATE_HARDWARE_VERTEXPROCESSING,&d3dpp,&d3ddev);
return;
}
//the 2nd function is to render a frame
void render_frame(void)
{
d3ddev->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,40,100),1.0f,0);
d3ddev->BeginScene();
d3ddev->EndScene();
d3ddev->Present(NULL,NULL,NULL,NULL);
return;
}
//third function to clear the memory...;)
void cleanD3D(void)
{
//nothing too fancy.. just some simple cleaning up...
d3ddev->Release();
d3d->Release();
return;
}
this is my program.. and i'm pretty sure i'v gone wrong with linking the files or something.. i'v included all the includes and lib files.. is there anything else i need to do.. i remember my professor in college doing something like going to project>settings>links and adding some lib files there like winmm.lib d3dx9.lib etc.. pls help.....