# Noob DirectX Problem

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

## Recommended Posts

When compiling my DirectX initialisation code I get the following error: 1>main.obj : error LNK2019: unresolved external symbol _Direct3DCreate9@4 referenced in function "long __cdecl InitialiseD3D(struct HWND__ *)" (?InitialiseD3D@@YAJPAUHWND__@@@Z) Can anyone indicate where I could possibly be going wrong? I've added the include and library folders to the linker directories (VC8) and I've also added the additional dependencies. Heres my code:
#include <d3d9.h>

LPDIRECT3D9 g_pD3D = NULL;
LPDIRECT3DDEVICE9 g_pD3DDevice = NULL;

HRESULT InitialiseD3D(HWND hWnd)
{
//First of all, create the main D3D object. If it is created successfully we
//should get a pointer to an IDirect3D8 interface.
g_pD3D = Direct3DCreate9(D3D_SDK_VERSION);
if(g_pD3D == NULL)
{
return E_FAIL;
}

//Get the current display mode
D3DDISPLAYMODE d3ddm;
{
return E_FAIL;
}

//Create a structure to hold the settings for our device
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));

//Fill the structure.
//We want our program to be windowed, and set the back buffer to a format
//that matches our current display mode
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = ::D3DSWAPEFFECT_FLIP;
d3dpp.BackBufferFormat = d3ddm.Format;

//Create a Direct3D device.
D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pD3DDevice)))
{
return E_FAIL;
}

return S_OK;
}



##### Share on other sites
Quote:
 Original post by MushuAlso link in d3d9.lib and d3dx9.lib, if you haven't already.

##### Share on other sites
Hmm this error seems fermiliar i think i had same prob if i can find the code i made than ill let you know and help u further.

##### Share on other sites
It is Visual C++ 2005 Express Edition.

##### Share on other sites
That is definitely a linker error, which means you either don't have the libraries properly linked, or you aren't including the correct header that contains that function.

Just for giggles place the following in your code:

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

#include <d3d9.h>
#include <d3dx9.h>

I don't think Direct3DCreate9 is in the D3DX library or header, but try it anyway. Make sure you clean and then rebuild.

##### Share on other sites
You need to link with d3d9.lib. If you are, make sure that you have the DX SDK lib directory listed in the VC lib paths, also check to make sure that there are no other d3d9.lib either in your program directory or in one of the other VC lib paths.

##### Share on other sites
I'd like to thank everyone for their help. I checked the VC++ directories and the library and include paths were all set fine. On a last hope I changed the lib path from:

C:\Program Files\Microsoft DirectX SDK (June 2006)\Lib\x64

to

C:\Program Files\Microsoft DirectX SDK (June 2006)\Lib\x86

and it now works!

Thanks

Afternote: Whats the difference between x64 and x86?

##### Share on other sites
Quote:
 Original post by ReganoI'd like to thank everyone for their help. I checked the VC++ directories and the library and include paths were all set fine. On a last hope I changed the lib path from:C:\Program Files\Microsoft DirectX SDK (June 2006)\Lib\x64to C:\Program Files\Microsoft DirectX SDK (June 2006)\Lib\x86and it now works!ThanksAfternote: Whats the difference between x64 and x86?

x64 is the libraries for the 64bit Windows. If you write your code to take advantage of 64bit and compile using 64bit specific libraries, you, in theory, should have a more optimized application.

x86 is the libraries for the average 32bit Windows, which 64bit will emulate so you can't go wrong.

• 10
• 18
• 14
• 18
• 15