|
#include "stdafx.h"
#include <initguid.h>
#include "VCGenie.h"
#include "DSAddIn.h"
#include "Commands.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CComModule _Module;
BEGIN_OBJECT_MAP(ObjectMap)
OBJECT_ENTRY(CLSID_DSAddIn, CDSAddIn)
END_OBJECT_MAP()
class CVCGenieApp : public CWinApp
{
public:
CVCGenieApp();
//{{AFX_VIRTUAL(CVCGenieApp)
public:
virtual BOOL InitInstance();
virtual int ExitInstance();
//}}AFX_VIRTUAL
//{{AFX_MSG(CVCGenieApp)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(CVCGenieApp, CWinApp)
//{{AFX_MSG_MAP(CVCGenieApp)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
CVCGenieApp theApp;
CVCGenieApp::CVCGenieApp()
{
}
BOOL CVCGenieApp::InitInstance()
{
_Module.Init(ObjectMap, m_hInstance);
return CWinApp::InitInstance();
}
int CVCGenieApp::ExitInstance()
{
_Module.Term();
return CWinApp::ExitInstance();
}
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
return _Module.GetClassObject(rclsid, riid, ppv);
}
STDAPI DllCanUnloadNow(void)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
return (AfxDllCanUnloadNow()==S_OK && _Module.GetLockCount()==0) ? S_OK : S_FALSE;
}
STDAPI DllRegisterServer(void)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
HRESULT hRes = S_OK;
// Registers object, typelib and all interfaces in typelib
hRes = _Module.RegisterServer(TRUE);
if (FAILED(hRes))
return hRes;
// Register description of this add-in object in its own
// "/Description" subkey.
// TODO: If you add more add-ins to this module, you need
// to register all of their descriptions, each description
// in each add-in object's registry CLSID entry:
// HKEY_CLASSES_ROOT\Clsid\{add-in CLSID}\Description="add-in description"
_ATL_OBJMAP_ENTRY* pEntry = _Module.m_pObjMap;
CRegKey key;
LONG lRes = key.Open(HKEY_CLASSES_ROOT, _T("CLSID"));
if (lRes == ERROR_SUCCESS)
{
USES_CONVERSION;
LPOLESTR lpOleStr;
StringFromCLSID(*pEntry->pclsid, &lpOleStr);
LPTSTR lpsz = OLE2T(lpOleStr);
lRes = key.Open(key, lpsz);
if (lRes == ERROR_SUCCESS)
{
CString strDescription;
strDescription.LoadString(IDS_VCGENIE_DESCRIPTION);
key.SetKeyValue(_T("Description"), strDescription);
}
CoTaskMemFree(lpOleStr);
}
if (lRes != ERROR_SUCCESS)
hRes = HRESULT_FROM_WIN32(lRes);
return hRes;
}
STDAPI DllUnregisterServer(void)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
HRESULT hRes = S_OK;
_Module.UnregisterServer();
return hRes;
}
#ifdef _DEBUG
void GetLastErrorDescription(CComBSTR& bstr)
{
CComPtr<IErrorInfo> pErrorInfo;
if (GetErrorInfo(0, &pErrorInfo) == S_OK)
pErrorInfo->GetDescription(&bstr);
}
#endif //_DEBUG
void ReportComError(HRESULT hr, LPCTSTR Code, LPCTSTR File, int Line)
{
TCHAR szDesc[300];
CString strMsg;
if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, (DWORD)hr,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), szDesc, 300, NULL)>0)
{
strMsg.Format(IDS_COMCHECK_MSG,
hr, szDesc, Code, File, Line);
}
else
{
strMsg.Format(IDS_COMCHECK_MSG,
hr, _T(""), Code, File, Line);
}
AfxMessageBox((LPCTSTR)strMsg, MB_ICONEXCLAMATION);
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.