I'm attempting to export a pointer to a new object from a DLL (Factory pattern), and I'm having a bit of a problem. Looking through the debugger it shows that the pointer is indeed not NULL, but the virtual table does not seem to appear (the debugger says: __vfptr CXX0030: Error: expression cannot be evaluated) and crashes when one of the virtual methods are called.
Here's the calling code:
bool VideoTask::start(void)
{
// we need to load the video library from the DLL
if(!libraryManager()->load( &m_pDevice, "glDevice.dll" ))
return false;
m_pDevice->Test();
return true;
}
And the library loading function:
template<class Tp> bool load(Tp** pFactory,string szFilepath)
{
// we need a path to work with anything right?
if(szFilepath.empty())
return false;
// load the library and return the pointer (through OS specific functions)
typedef Tp* (*libFunc_t)();
void* hLib = Platform::LoadLibrary( szFilepath.c_str() );
if(!hLib)
{
Platform::MessageBox("Error","Failed loading DLL; please check your installation.");
return false;
}
libFunc_t pfnExport = reinterpret_cast<libFunc_t> (Platform::GetProcAddress(hLib, "ExportAPI"));
if(!pfnExport)
{
Platform::MessageBox("Error","Failed getting function address; please check your installation.");
Platform::FreeLibrary(hLib);
return false;
}
(*pFactory) = pfnExport();
m_List.push_back( hLib );
return true;
}
The Platform:: calls are wrappers to the Win32 API, I've attempted the code with and without the wrapper calls and the same results happen. So I've decided to leave the wrapper calls in. The code dies when m_pDevice->Test() is called.
Thanks for the help ahead of time!