Initializing DirectX 9

Started by
4 comments, last by djoseph74 19 years, 10 months ago
Hi Everyone, I''m using Visual C++ .NET 2003 and DirectX 9. I''ve made a simple program that does nothing more than create a Win32 window, then initialize directx and sit there waiting for you to either close it or right click. If you right-click, it gives a MessageBox with a simple message. I tested this out without the Direct3D 9 stuff in there. It opens the window, accepts the right-click ok. I add in the D3D stuff and I get these errors on compile: win_main.obj : error LNK2019: unresolved external symbol _Direct3DCreate9@4 referenced in function _WinMain@16 Debug/Space Invaders 3D.exe : fatal error LNK1120: 1 unresolved externals I have no idea what this means. Could someone tell me what I''ve done wrong? I grabbed a tutorial ZIP from gametutorials.com, it compiles ok. Must be me.. Source code is below.. -Dan Joseph

#include <windows.h>
#include <d3d9.h>

#define class_name "SpaceInvaders"

LRESULT CALLBACK WinProc( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam );

int WINAPI WinMain( HINSTANCE hinstance, HINSTANCE hprev, PSTR cmdline, int ishow )
{
	HWND hwnd;
	MSG  msg;
	RECT rect;

	WNDCLASSEX wndclassex = {0};

	IDirect3D9 *g_D3D = NULL;

	g_D3D = Direct3DCreate9( D3D_SDK_VERSION );

	if ( !g_D3D )
	{
		return EXIT_FAILURE;
	}
	else if ( g_D3D )
	{
		g_D3D->Release();
		g_D3D = NULL;
	}

	wndclassex.cbSize           = sizeof( WNDCLASSEX );
	wndclassex.style            = CS_HREDRAW | CS_VREDRAW;
	wndclassex.lpfnWndProc      = WinProc;
	wndclassex.hInstance        = hinstance;
	wndclassex.hbrBackground    = (HBRUSH)GetStockObject( WHITE_BRUSH );
	wndclassex.lpszClassName    = class_name;
	wndclassex.hCursor          = (HCURSOR)LoadImage( NULL, MAKEINTRESOURCE( IDC_ARROW ), IMAGE_CURSOR, 0, 0, LR_SHARED );

	RegisterClassEx( &wndclassex );

	DWORD winStyleEx = WS_EX_CLIENTEDGE;
	DWORD winStyle   = WS_CAPTION | WS_SYSMENU | WS_MAXIMIZEBOX | WS_MINIMIZEBOX;

	hwnd = CreateWindowEx( winStyleEx,
						   class_name,
						   "Space Invaders 3D",
						   winStyle,
						   CW_USEDEFAULT,
						   CW_USEDEFAULT,
						   800,
						   600,
						   NULL,
						   NULL,
						   hinstance,
						   NULL                    );

	GetClientRect( hwnd, &rect );

	ShowWindow( hwnd, ishow );
	UpdateWindow( hwnd );

	while ( 1 )
	{
		if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
		{
			if ( msg.message == WM_QUIT )
				break;

			TranslateMessage( &msg );
			DispatchMessage( &msg );
		}
	}

	return 0;
}

LRESULT CALLBACK WinProc( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam )
{
	switch ( message )
	{
		case WM_LBUTTONDOWN:
			MessageBox( 0, "Hello DirectX 9!", "Hello", MB_OK );
			return 0;

		case WM_DESTROY:
			PostQuitMessage( 0 );
			return 0;
	}

	return DefWindowProc( hwnd, message, wparam, lparam );
}
Advertisement
Are your library paths correct? Sometimes VC tries to link to an older library of DirectX.

Also, are you linking with dxguid.lib? Make sure you do that or define INITGUID.
Apparently that''s exactly what it is. I added a line too it:

#pragma comment(lib, "d3d9.lib")

It seems to have solved that problem. I''ll have to figure out how to setup Vis Studio properly. I must have done something wrong.

I appreciate your help, much appreciated.. you made my night.

-Dan Joseph
Setting up VC correctly:

1. Go to Project->Settings
2. Click the ''Link'' tab
3. In ''Object/library modules'', type in the libraries you want included (space-delimited)


-- Fyhuang, president, Altitude Technologies

Altitude Technologies: http://www.hytetech.com/altitude
Altitude Forums: http://s8.invisionfree.com/Altitude_Forums/
- fyhuang [ site ]
Hmm.. I''m going to the Project menu, but I have no ''Settings'' option.. Is there something I have to do to get it to appear?

-Dan Joseph
Ahh you know what, you''re directing for VC 6.0, I have 7.0 (.NET 2003).. Its under Project->Properties. I have the libs in there now, thanks a bunch. didn''t realize I had to do that for each new project. I should have known... lol

-Dan Joseph

This topic is closed to new replies.

Advertisement