I have written a class that uses DirectX9 to create surfaces, but I get linker-errors.
The errors seems to be in the CXSurface::LoadFromFile(const char* Path).
The source-code comes from the book
"DirectX 9 User Interfaces Design and Implementation".
Here are the errors:
1>------ Build started: Project: UILib, Configuration: Release Win32 ------
1>Compiling...
1>main.cpp
1>h:\programmering\visual c++ 2005\uilib\uilib\main.cpp(34) : warning C4700: uninitialized local variable 'msg' used
1>Linking...
1>main.obj : error LNK2019: unresolved external symbol _D3DXLoadSurfaceFromFileA@32 referenced in function "public: long __thiscall CXSurface::LoadFromFile(char const *)" ( LoadFromFile@CXSurface@@QAEJPBD@Z)
1>main.obj : error LNK2019: unresolved external symbol _D3DXGetImageInfoFromFileA@8 referenced in function "public: long __thiscall CXSurface::LoadFromFile(char const *)" ( LoadFromFile@CXSurface@@QAEJPBD@Z)
1>H:\Programmering\Visual C++ 2005\UILib\Release\UILib.exe : fatal error LNK1120: 2 unresolved externals
1>Build log was saved at "file://h:\Programmering\Visual C++ 2005\UILib\UILib\Release\BuildLog.htm"
1>UILib - 3 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Here's the class I'm using in my project:
class CXSurface
{
private:
LPDIRECT3DSURFACE9 m_Surface;
LPDIRECT3DDEVICE9 m_pDevice;
protected:
public:
CXSurface();
CXSurface(LPDIRECT3DDEVICE9 pDevice);
CXSurface(LPDIRECT3DDEVICE9 pDevice, const char* Path);
~CXSurface();
LPDIRECT3DSURFACE9 GetSurface() {return m_Surface;}
void SetSurface(LPDIRECT3DSURFACE9 Surf) {m_Surface = Surf;}
LPDIRECT3DDEVICE9 GetDevice() {return m_pDevice;}
void SetDevice(LPDIRECT3DDEVICE9 pDevice) {m_pDevice = pDevice;}
HRESULT CreateSurface(UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool);
HRESULT LoadFromFile(const char* Path);
HRESULT MakeBackBuffer(void);
HRESULT PasteFromSurface(CXSurface* Source, RECT* pSourceRect, int X, int Y);
void Render();
};
CXSurface::CXSurface()
{
this->SetDevice(NULL);
this->SetSurface(NULL);
}
CXSurface::CXSurface(LPDIRECT3DDEVICE9 pDevice)
{
this->SetDevice(pDevice);
this->SetSurface(NULL);
}
CXSurface::CXSurface(LPDIRECT3DDEVICE9 pDevice, const char* Path)
{
this->SetDevice(pDevice);
this->SetSurface(NULL);
this->LoadFromFile(Path);
}
CXSurface::~CXSurface()
{
if(m_Surface)
m_Surface->Release();
}
HRESULT CXSurface::LoadFromFile(const char* Path)
{
HRESULT Result = E_FAIL;
D3DXIMAGE_INFO Info;
ZeroMemory(&Info,sizeof(D3DXIMAGE_INFO));
if (SUCCEEDED(D3DXGetImageInfoFromFile(Path, &Info)))
{
Result = this->CreateSurface(Info.Width,
Info.Height,
Info.Format,
D3DPOOL_SYSTEMMEM);
}
if(Result == S_OK)
Result = D3DXLoadSurfaceFromFile(this->m_Surface, NULL, NULL,
Path, NULL, D3DX_FILTER_NONE, 0, NULL);
else
Result = E_FAIL;
return Result;
}
HRESULT CXSurface::CreateSurface(UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool)
{
if(m_Surface)
m_Surface->Release();
if(m_pDevice)
return m_pDevice->CreateOffscreenPlainSurface(Width, Height, Format,
Pool, &m_Surface, NULL);
else
return E_FAIL;
}
HRESULT CXSurface::MakeBackBuffer(void)
{
if(m_pDevice)
{
if(m_Surface)
m_Surface->Release();
return m_pDevice->GetBackBuffer(0,0, D3DBACKBUFFER_TYPE_MONO, &m_Surface);
}
else
return E_FAIL;
}
HRESULT CXSurface::PasteFromSurface(CXSurface* Source, RECT* pSourceRect, int X, int Y)
{
if((m_pDevice) && (Source))
{
POINT Point;
Point.x = X;
Point.y = Y;
return m_pDevice->UpdateSurface(Source->GetSurface(), pSourceRect,
this->m_Surface, NULL);
}
else
return E_FAIL;
}
void CXSurface::Render()
{
m_pDevice->UpdateSurface(this->GetSurface(), NULL, 0, 0);
}
Does anyone know what's wrong

Problems with class that creates DirectX9-Surfaces
MusicMan756
I had to do some (very big) changes in the .cpp-file.
Sudeesh
I have solved the problem, but now I get a runtime-error:
Unhandled exception at 0x00401007 in UILib.exe: 0xC0000005: Access violation reading location 0x00000000.
The same error is both in Debug and Release.
brewewa
I hope this helps.
take care.
Brian Herdeg
LINK error is when the compiler find the definition but not the implementation
So it's most of the time it's because it cannot find the lib or because you define a function but you didn't define the implementation for it
Here he can't find the lib...so to answer we need to know the version of IDE
you are using...because it's probably that in the Menu of your IDE
in the section where you point to your lib and include directory
the compiler don't find the lib you need
Make sure that the lib that goes with the *.h file you use is in the directory that you use
When the function itself is call with a bad parameter the compiler error is different
It will tell you he can't find the function even with parameters look-up...
So here the definition is probably OK and the *.h is OK, it's the lib he can't find