annotate src/VisVim/VisVim.cpp @ 20781:93e66f657101

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