// Retrieves the address of an exported function or variable from the specified dynamic-link library (DLL).
typedef void (* LPFN_MYFUNCTION)(void);
LPFN_MYFUNCTION lpfnMyFunction;
CuDllManager DllManager;
BOOL bLoadDll = DllManager.LoadLibrary(L"dllfile.dll");
lpfnMyFunction = (LPFN_MYFUNCTION)DllManager.GetProcAddress("MyFunction");
// CuDllManager.h
class CuDllManager
{
private:
HINSTANCE m_hinstDll;
public:
virtual FARPROC GetProcAddress(LPCSTR lpProcName);
virtual void FreeLibrary();
virtual BOOL LoadLibrary(LPCTSTR szLibrary);
CuDllManager();
virtual ~CuDllManager();
};
// CuDllManager.cpp
CuDllManager::CuDllManager()
{
m_hinstDll = NULL;
}
CuDllManager::~CuDllManager()
{
FreeLibrary();
}
BOOL CuDllManager::LoadLibrary(LPCTSTR szLibrary)
{
FreeLibrary();
m_hinstDll = ::LoadLibrary(szLibrary);
return (BOOL)m_hinstDll != NULL;
}
void CuDllManager::FreeLibrary()
{
if( m_hinstDll != NULL )
{
::FreeLibrary(m_hinstDll);
m_hinstDll = NULL;
}
}
FARPROC CuDllManager::GetProcAddress(LPCSTR lpProcName)
{
return ::GetProcAddress(m_hinstDll, lpProcName);
}
2009年12月23日 星期三
CuDllManager - Retrieves the address of an exported function or variable from the specified dynamic-link library (DLL).
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言