1 // VisVile.cpp : Defines the initialization routines for the DLL.
2 //
3
4 #include "stdafx.h"
5 #include <initguid.h>
6 #include "VisVile.h"
7 #include "DSAddIn.h"
8 #include "Commands.h"
9
10
11 #ifdef _DEBUG
12 #define new DEBUG_NEW
13 #undef THIS_FILE
14 static char THIS_FILE[] = __FILE__;
15 #endif
16
17 CComModule _Module;
18
19 BEGIN_OBJECT_MAP(ObjectMap)
20 OBJECT_ENTRY(CLSID_DSAddIn, CDSAddIn)
21 END_OBJECT_MAP()
22
23 /////////////////////////////////////////////////////////////////////////////
24 // CVisVileApp
25
26 class CVisVileApp : public CWinApp
27 {
28 public:
29 CVisVileApp();
30
31 // Overrides
32 // ClassWizard generated virtual function overrides
33 //{{AFX_VIRTUAL(CVisVileApp)
34 public:
35 virtual BOOL InitInstance();
36 virtual int ExitInstance();
37 //}}AFX_VIRTUAL
38
39 //{{AFX_MSG(CVisVileApp)
40 // NOTE - the ClassWizard will add and remove member functions here.
41 // DO NOT EDIT what you see in these blocks of generated code !
42 //}}AFX_MSG
43 DECLARE_MESSAGE_MAP()
44 };
45
46
47 /////////////////////////////////////////////////////////////////////////////
48 // CVisVileApp
49
50 BEGIN_MESSAGE_MAP(CVisVileApp, CWinApp)
51 //{{AFX_MSG_MAP(CVisVileApp)
52 // NOTE - the ClassWizard will add and remove mapping macros here.
53 // DO NOT EDIT what you see in these blocks of generated code!
54 //}}AFX_MSG_MAP
55 END_MESSAGE_MAP()
56
57 /////////////////////////////////////////////////////////////////////////////
58 // The one and only CVisVileApp object
59
60 CVisVileApp theApp;
61
62 /////////////////////////////////////////////////////////////////////////////
63 // CVisVileApp construction
64
CVisVileApp()65 CVisVileApp::CVisVileApp()
66 {
67 }
68
69 /////////////////////////////////////////////////////////////////////////////
70 // CVisVileApp initialization
71
InitInstance()72 BOOL CVisVileApp::InitInstance()
73 {
74 _Module.Init(ObjectMap, m_hInstance);
75 return CWinApp::InitInstance();
76 }
77
ExitInstance()78 int CVisVileApp::ExitInstance()
79 {
80 _Module.Term();
81 return CWinApp::ExitInstance();
82 }
83
84 /////////////////////////////////////////////////////////////////////////////
85 // Special entry points required for inproc servers
86
DllGetClassObject(REFCLSID rclsid,REFIID riid,LPVOID * ppv)87 STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
88 {
89 AFX_MANAGE_STATE(AfxGetStaticModuleState());
90 return _Module.GetClassObject(rclsid, riid, ppv);
91 }
92
DllCanUnloadNow(void)93 STDAPI DllCanUnloadNow(void)
94 {
95 AFX_MANAGE_STATE(AfxGetStaticModuleState());
96 return (AfxDllCanUnloadNow()==S_OK && _Module.GetLockCount()==0) ? S_OK : S_FALSE;
97 }
98
99 // by exporting DllRegisterServer, you can use regsvr32.exe
DllRegisterServer(void)100 STDAPI DllRegisterServer(void)
101 {
102 AFX_MANAGE_STATE(AfxGetStaticModuleState());
103 HRESULT hRes = S_OK;
104
105 // Registers object, typelib and all interfaces in typelib
106 hRes = _Module.RegisterServer(TRUE);
107 if (FAILED(hRes))
108 return hRes;
109
110 // Register description of this add-in object in its own
111 // "/Description" subkey.
112 _ATL_OBJMAP_ENTRY* pEntry = _Module.m_pObjMap;
113 CRegKey key;
114 LONG lRes = key.Open(HKEY_CLASSES_ROOT, _T("CLSID"));
115 if (lRes == ERROR_SUCCESS)
116 {
117 USES_CONVERSION;
118 LPOLESTR lpOleStr;
119 StringFromCLSID(*pEntry->pclsid, &lpOleStr);
120 LPTSTR lpsz = OLE2T(lpOleStr);
121
122 lRes = key.Open(key, lpsz);
123 if (lRes == ERROR_SUCCESS)
124 {
125 CString strDescription;
126 strDescription.LoadString(IDS_VISVILE_DESCRIPTION);
127 key.SetKeyValue(_T("Description"), strDescription);
128 }
129 CoTaskMemFree(lpOleStr);
130 }
131 if (lRes != ERROR_SUCCESS)
132 hRes = HRESULT_FROM_WIN32(lRes);
133
134 return hRes;
135 }
136
137 /////////////////////////////////////////////////////////////////////////////
138 // DllUnregisterServer - Removes entries from the system registry
139
DllUnregisterServer(void)140 STDAPI DllUnregisterServer(void)
141 {
142 AFX_MANAGE_STATE(AfxGetStaticModuleState());
143
144 HRESULT hRes = S_OK;
145 _Module.UnregisterServer();
146 return hRes;
147 }
148