0

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.....

3
Contributors
10
Replies
11
Views
8 Years
Discussion Span
Last Post by jbennet
0

Which version of directx sdk are you using? the most recent ones only support Visual Studio 2005 and above.

0

i'm using aug 2008 release.. and visual studio 6.. so upgrading to a higher version of vs is the solution??

0

alright.. i downloaded visual studio 2008 express edition... still that above program won't work.. this is what i get when i run the program....

1>------ Build started: Project: initializedx, Configuration: Debug Win32 ------
1>Embedding manifest...
1>The system cannot find the path specified.
1>Project : error PRJ0002 : Error result 1 returned from 'C:\WINDOWS\system32\cmd.exe'.
1>Build log was saved at "file://f:\vs progs\new\initializedx\initializedx\Debug\BuildLog.htm"
1>initializedx - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


any help??

0

and how exactly do i do that?? after installing i went to tools>options>VC++ directories and added the dx sdk includes and library files.. i did not do anything apart from this.. do i need to do something else??

0

was it the environent variable?

I had that issue a while ago trying to get an older version if the DXSDK working with VC#.NET 2003 and NET 1.1. Seems it doesnt always register it properley.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.