Sign in to follow this  

Direct X Init functions in header file problems

This topic is 4689 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

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 this post


Link to post
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 this post


Link to post
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.h

class Graphics
{
void Initialise();
};


and in the graphics.cpp

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


Edit: glad to help :)

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

This topic is 4689 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this