level 1
Lion1942
楼主
DLL中定义:
box.h
class _dec
lsp
ec(dllexport) box{
public:
box(){};
double volume();
static box* Init();
static box* pbox;
};
box.cpp
box* box::pbox = 0;
double box::volume()
{
return 10;
}
box* box::Init()
{
if(pbox==0)
{
pbox = new box();
}
return pbox;
};
程序中定义:
定义box.h头文件,不定义源文件:
box.h
class _declspec(dllimport) box{
public:
box(){};
double volume();
static box* Init();
static box* pbox;
};
在调用函数中获取到插件实例:
HINSTANCE m_hInst = LoadLibrary("DLL名称"); //可以正常获取
typedef box* (*m_pFunction)();
typedef double (*pVolume)();
m_pFunction pFun = (m_pFunction)GetProcAddress(m_hInst,"Init"); //可以获取
box* pbox = (*PFun)(); //可以取得
int number = pbox->volume(); //此处出错,为什么?
2012年10月14日 13点10分
1
box.h
class _dec
lsp
ec(dllexport) box{
public:
box(){};
double volume();
static box* Init();
static box* pbox;
};
box.cpp
box* box::pbox = 0;
double box::volume()
{
return 10;
}
box* box::Init()
{
if(pbox==0)
{
pbox = new box();
}
return pbox;
};
程序中定义:
定义box.h头文件,不定义源文件:
box.h
class _declspec(dllimport) box{
public:
box(){};
double volume();
static box* Init();
static box* pbox;
};
在调用函数中获取到插件实例:
HINSTANCE m_hInst = LoadLibrary("DLL名称"); //可以正常获取
typedef box* (*m_pFunction)();
typedef double (*pVolume)();
m_pFunction pFun = (m_pFunction)GetProcAddress(m_hInst,"Init"); //可以获取
box* pbox = (*PFun)(); //可以取得
int number = pbox->volume(); //此处出错,为什么?