Pregunta

I have been going through my code for days, change bits of codes to see if they work, try different methods to use my code yet I am still getting that annoying LNK2019 error.

This is the original error message.

Error 1 error LNK2019: unresolved external symbol "public: struct IDirect3DSurface9 * thiscall CRenderer::LoadSurface(wchar_t const *,unsigned long,struct IDirect3DDevice9 *)" (?LoadSurface@CRenderer@@QAEPAUIDirect3DSurface9@@PB_WKPAUIDirect3DDevice9@@@Z) referenced in function "public: void __thiscall CGame::InitGame(struct HWND *,int,int,bool)" (?InitGame@CGame@@QAEXPAUHWND__@@HH_N@Z) J:\Workspace\Fruit Avengers\Game.obj

This is the code where I believe the problem is. I have used this code in previous project which worked. I just don't know why it didn't work this time round.

Renderer.h

class CRenderer
{
public:
    IDirect3DTexture9* LoadTexture( LPCSTR FileName, D3DCOLOR Alpha, IDirect3DDevice9* Device );
    IDirect3DSurface9* LoadSurface( LPCWSTR FileName, D3DCOLOR Alpha, IDirect3DDevice9* Device );
};

Renderer.cpp

IDirect3DSurface9* CRenderer::LoadSurface( LPCWSTR FileName, D3DCOLOR Alpha, IDirect3DDevice9* Device )
{
    IDirect3DSurface9* Result = NULL;
    D3DXIMAGE_INFO Info;
    D3DXGetImageInfoFromFileW( FileName, &Info );
    Device->CreateOffscreenPlainSurface( Info.Width, Info.Height, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &Result, NULL );
    D3DXLoadSurfaceFromFileW( Result, NULL, NULL, FileName, NULL, D3DX_DEFAULT, Alpha, NULL );
    return Result;
}

Game.cpp

void CGame::InitGame( HWND hWnd, int Width, int Height, bool Windowed )
{
    //Initialize Includes
    Graphics.InitDirect3D( hWnd, Width, Height, Windowed );

    //Load Game Variables...

    //Load Game Media...
    MenuBackground = WWIRenderer.LoadSurface( L"Resource/MenuBackground.jpg", 0, Graphics.Direct3DDevice );
   //^
}

EDIT: Before anyone ask, I've done some searching but the answers that I've found are not that helpful.

¿Fue útil?

Solución 2

When compiling with MSVC++, every source and header files must be added to the Solution Explorer otherwise you will get the LNK2019 error. Thank you Uchia.

Otros consejos

As I remember right, this is a Error that occurs if you ahve not installed the DirectX SDK. So you should do so, or maybe reinstall it or update it.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top