Direct X Init functions in header file problems

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

Recommended Posts

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

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

Share on other sites
yeah, that was it....

I always forget to link the library files. thanks stevenmarky

Share on other sites
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}

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

1. 1
2. 2
3. 3
Rutin
20
4. 4
5. 5
khawk
14

• 9
• 11
• 11
• 23
• 10
• Forum Statistics

• Total Topics
633653
• Total Posts
3013152
×