// 注册
BOOL CDllRegister::Register(CString strDll)
{
CString strLastErr = _T("");
BOOL bResult = FALSE;
HMODULE hModule = ::LoadLibrary(strDll);
if (LOADLIBRARY_FAILED(hModule))
{
strLastErr.Format(_T("%s\r\n载入失败(::GetLastError()=0x%.8X)"), strDll, ::GetLastError());
return FALSE;
}
CTLREGPROC DLLRegisterServer = (CTLREGPROC)::GetProcAddress(hModule, "DllRegisterServer");
if (DLLRegisterServer != NULL)
{
HRESULT regResult = DLLRegisterServer();
bResult = (regResult == NOERROR);
if (!bResult)
{
strLastErr.Format(_T("%s\r\n注册函数执行失败(HRESULT=0x%.8X)"), strDll, regResult);
}
}
::FreeLibrary(hModule);
return bResult;
}
// 反注册
BOOL CDllRegister::UnRegister(CString strDll){
CString strLastErr = _T("");
BOOL bResult = FALSE;
HMODULE hModule = ::LoadLibrary(strDll);
if (LOADLIBRARY_FAILED(hModule))
{
strLastErr.Format(_T("载入失败\r\n%s"), strDll);
return FALSE;
}
CTLREGPROC DllUnregisterServer = (CTLREGPROC)::GetProcAddress(hModule, "DllUnregisterServer");
if (DllUnregisterServer != NULL)
{
HRESULT regResult = DllUnregisterServer();
bResult = (regResult == NOERROR);
if (!bResult)
{
strLastErr.Format(_T("注册函数执行失败\r\n%s"), strDll);
}
}
::FreeLibrary(hModule);
return bResult;
}