Direct X Init functions in header file problems

Started by
3 comments, last by CreepingDeath666 19 years, 2 months ago
I want to put all of my direct x functions into a header file so that my .cpp file will look clean. this is my function to initialize d3d: HRESULT InitD3D( HWND hWnd ) { if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) ) return E_FAIL; D3DPRESENT_PARAMETERS d3dpp; ZeroMemory( &d3dpp, sizeof(d3dpp) ); d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = D3DFMT_UNKNOWN; if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pd3dDevice ) ) ) { return E_FAIL; } return S_OK; } I include <d3d9.h> into my header file and .cpp file and I still get this link error: error LNK2019: unresolved external symbol _Direct3DCreate9@4 referenced in function "long __cdecl InitD3D(struct HWND__ *)" (?InitD3D@@YAJPAUHWND__@@@Z) it's not liking the: if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) ) return E_FAIL; please help
Advertisement
As well as linking to the .h file, you have to link to the actualy .lib file that the code is stored in.
If you are using Microsoft Visual C++ or such you can go to project settings -> link and add 'd3d9.lib' to the list of libraries. I think this is your problem.
yeah, that was it....

I always forget to link the library files. thanks stevenmarky
Also I don't understand your first comment; you can have as many .h files or cpp files as you want. I usually find it best to only have interfaces in the *.h file and the actual code in the cpp files.

e.g.
graphics.hclass Graphics{void Initialise();};


and in the graphics.cpp
#include "graphics.h"void Graphics::Initialise(){...insert your stuff here}


Edit: glad to help :)
oh, yeah, I will have a .h for each aspect such as: sound.h, graphics.h, render.h, etc...

that .h file I was talking about is used just to initialize direct x and to set up the windows functions so I wouldn't have to in my main .cpp file

This topic is closed to new replies.

Advertisement