1// VisVim.cpp : Defines the initialization routines for the DLL. 2// 3 4#include "stdafx.h" 5#include <initguid.h> 6#include "VisVim.h" 7#include "DSAddIn.h" 8#include "Commands.h" 9 10#ifdef _DEBUG 11#define new DEBUG_NEW 12#undef THIS_FILE 13static char THIS_FILE[] = __FILE__; 14 15#endif 16 17CComModule _Module; 18 19BEGIN_OBJECT_MAP (ObjectMap) 20OBJECT_ENTRY (CLSID_DSAddIn, CDSAddIn) 21END_OBJECT_MAP () 22 23class CVisVimApp : public CWinApp 24{ 25 public: 26 CVisVimApp (); 27 28 //{{AFX_VIRTUAL(CVisVimApp) 29 public: 30 virtual BOOL InitInstance (); 31 virtual int ExitInstance (); 32 //}}AFX_VIRTUAL 33 34 //{{AFX_MSG(CVisVimApp) 35 //}}AFX_MSG 36 DECLARE_MESSAGE_MAP () 37}; 38 39BEGIN_MESSAGE_MAP (CVisVimApp, CWinApp) 40//{{AFX_MSG_MAP(CVisVimApp) 41//}}AFX_MSG_MAP 42END_MESSAGE_MAP () 43 44// The one and only CVisVimApp object 45CVisVimApp theApp; 46 47CVisVimApp::CVisVimApp () 48{ 49} 50 51BOOL CVisVimApp::InitInstance () 52{ 53 _Module.Init (ObjectMap, m_hInstance); 54 return CWinApp::InitInstance (); 55} 56 57int CVisVimApp::ExitInstance () 58{ 59 _Module.Term (); 60 return CWinApp::ExitInstance (); 61} 62 63// Special entry points required for inproc servers 64// 65 66STDAPI DllGetClassObject (REFCLSID rclsid, REFIID riid, LPVOID * ppv) 67{ 68 AFX_MANAGE_STATE (AfxGetStaticModuleState ()); 69 return _Module.GetClassObject (rclsid, riid, ppv); 70} 71 72STDAPI DllCanUnloadNow (void) 73{ 74 AFX_MANAGE_STATE (AfxGetStaticModuleState ()); 75 return (AfxDllCanUnloadNow () == S_OK && _Module.GetLockCount () == 0) 76 ? S_OK : S_FALSE; 77} 78 79// By exporting DllRegisterServer, you can use regsvr32.exe 80// 81STDAPI DllRegisterServer (void) 82{ 83 AFX_MANAGE_STATE (AfxGetStaticModuleState ()); 84 HRESULT hRes; 85 86 // Registers object, typelib and all interfaces in typelib 87 hRes = _Module.RegisterServer (TRUE); 88 if (FAILED (hRes)) 89 // Hack: When this fails we might be a normal user, while the 90 // admin already registered the module. Returning S_OK then 91 // makes it work. When the module was never registered it 92 // will soon fail in another way. 93 // old code: return hRes; 94 return S_OK; 95 96 _ATL_OBJMAP_ENTRY *pEntry = _Module.m_pObjMap; 97 CRegKey key; 98 LONG lRes = key.Open (HKEY_CLASSES_ROOT, _T ("CLSID")); 99 100 if (lRes == ERROR_SUCCESS) 101 { 102 USES_CONVERSION; 103 LPOLESTR lpOleStr; 104 105 StringFromCLSID (*pEntry->pclsid, &lpOleStr); 106 LPTSTR lpsz = OLE2T (lpOleStr); 107 108 lRes = key.Open (key, lpsz); 109 if (lRes == ERROR_SUCCESS) 110 { 111 CString strDescription; 112 113 strDescription.LoadString (IDS_VISVIM_DESCRIPTION); 114 key.SetKeyValue (_T ("Description"), strDescription); 115 } 116 CoTaskMemFree (lpOleStr); 117 } 118 119 if (lRes != ERROR_SUCCESS) 120 hRes = HRESULT_FROM_WIN32 (lRes); 121 122 return hRes; 123 124} 125 126// DllUnregisterServer - Removes entries from the system registry 127// 128STDAPI DllUnregisterServer (void) 129{ 130 AFX_MANAGE_STATE (AfxGetStaticModuleState ()); 131 132 HRESULT hRes = S_OK; 133 _Module.UnregisterServer (); 134 return hRes; 135} 136 137 138// Debugging support 139 140// GetLastErrorDescription is used in the implementation of the VERIFY_OK 141// macro, defined in stdafx.h. 142 143#ifdef _DEBUG 144 145void GetLastErrorDescription (CComBSTR & bstr) 146{ 147 CComPtr < IErrorInfo > pErrorInfo; 148 if (GetErrorInfo (0, &pErrorInfo) == S_OK) 149 pErrorInfo->GetDescription (&bstr); 150} 151 152#endif //_DEBUG 153