• Advertisement

Archived

This topic is now archived and is closed to further replies.

Initializing DirectX 9

This topic is 4976 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 );
}

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • Advertisement