Direct X Init functions in header file problems
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
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.
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.
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.
and in the graphics.cpp
Edit: glad to help :)
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 :)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement