Stroika Library 3.0d18
 
Loading...
Searching...
No Matches
ActiveLedIt.cpp
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#include "Stroika/Foundation/StroikaPreComp.h"
5
6DISABLE_COMPILER_MSC_WARNING_START (5054)
7#include <afxctl.h>
8DISABLE_COMPILER_MSC_WARNING_END (5054)
9
10#include <comcat.h>
11#include <objsafe.h>
12
16
17#include "Stroika/Frameworks/Led/StyledTextEmbeddedObjects.h"
18
19#include "ActiveLedItControl.h"
20#include "Resource.h"
21#include "UserConfigCommands.h"
22
23#include "ActiveLedIt.h"
24
25#include "ActiveLedIt_i.c"
26
27inline const void* LoadDLLResource (long resID, LPCTSTR resType)
28{
29 HRSRC hrsrc = ::FindResource (::AfxGetResourceHandle (), MAKEINTRESOURCE (resID), resType);
30 AssertNotNull (hrsrc);
31 HGLOBAL hglobal = ::LoadResource (::AfxGetResourceHandle (), hrsrc);
32 const void* lockedData = ::LockResource (hglobal);
33 EnsureNotNull (lockedData);
34 return (lockedData);
35}
36
37// Support for registering in the ComponentCategoryManager - that we are a SAFE control, to avoid nasty warnings
38// when running embedded in IE
39static HRESULT CreateComponentCategory (CATID catid, const WCHAR* catDescription)
40{
41 ICatRegister* pcr = NULL;
42 HRESULT hr = S_OK;
43
44 hr = CoCreateInstance (CLSID_StdComponentCategoriesMgr, NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr);
45 if (FAILED (hr))
46 return hr;
47
48 // Make sure the HKCR\Component Categories\{..catid...}
49 // key is registered.
50 CATEGORYINFO catinfo;
51 catinfo.catid = catid;
52 catinfo.lcid = 0x0409; // english
53
54 // Make sure the provided description is not too long.
55 // Only copy the first 127 characters if it is.
56 size_t len = wcslen (catDescription);
57 if (len > 127)
58 len = 127;
59 Characters::CString::Copy (catinfo.szDescription, len, catDescription);
60
61 hr = pcr->RegisterCategories (1, &catinfo);
62 pcr->Release ();
63
64 return hr;
65}
66static HRESULT RegisterCLSIDInCategory (REFCLSID clsid, CATID catid)
67{
68 // Register your component categories information.
69 ICatRegister* pcr = NULL;
70 HRESULT hr = S_OK;
71 hr = CoCreateInstance (CLSID_StdComponentCategoriesMgr, NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr);
72 if (SUCCEEDED (hr)) {
73 // Register this category as being "implemented" by the class.
74 CATID rgcatid[1];
75 rgcatid[0] = catid;
76 hr = pcr->RegisterClassImplCategories (clsid, 1, rgcatid);
77 }
78
79 if (pcr != NULL)
80 pcr->Release ();
81
82 return hr;
83}
84static HRESULT UnRegisterCLSIDInCategory (REFCLSID clsid, CATID catid)
85{
86 ICatRegister* pcr = NULL;
87 HRESULT hr = S_OK;
88
89 hr = CoCreateInstance (CLSID_StdComponentCategoriesMgr, NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr);
90 if (SUCCEEDED (hr)) {
91 // Unregister this category as being "implemented" by the class.
92 CATID rgcatid[1];
93 rgcatid[0] = catid;
94 hr = pcr->UnRegisterClassImplCategories (clsid, 1, rgcatid);
95 }
96 if (pcr != NULL)
97 pcr->Release ();
98 return hr;
99}
100
101/*
102 ********************************************************************************
103 *********************************** ATL Support ********************************
104 ********************************************************************************
105 */
106#include <atlbase.h>
107
108namespace {
109 class ActiveLedItModule : public CAtlMfcModule { /*CAtlDllModuleT <ActiveLedItModule>*/
110 public:
111 DECLARE_LIBID (LIBID_ACTIVELEDITLib)
112 };
113 ActiveLedItModule _AtlModule;
114}
115
116/*
117 ********************************************************************************
118 ******************************** ActiveLedItApp ********************************
119 ********************************************************************************
120 */
121
122ActiveLedItApp theApp;
123
124const GUID CDECL BASED_CODE _tlid = {0x9a013a72, 0xad34, 0x11d0, {0x8d, 0x9b, 0, 0xa0, 0xc9, 0x8, 0xc, 0x73}};
125const WORD _wVerMajor = qLed_Version_Major;
126const WORD _wVerMinor = qLed_Version_Minor;
127
128BOOL ActiveLedItApp::InitInstance ()
129{
130 SetRegistryKey (_T ("Sophist Solutions, Inc."));
131
132 BOOL bInit = inherited::InitInstance ();
133
134 if (bInit) {
135 // Tell Led about the picture resources it needs to render some special embedding markers
136 StandardUnknownTypeStyleMarker::sUnknownPict = (const Led_DIB*)::LoadDLLResource (kUnknownEmbeddingPictID, RT_BITMAP);
137 StandardMacPictureStyleMarker::sUnsupportedFormatPict = (const Led_DIB*)::LoadDLLResource (kUnsupportedPICTFormatPictID, RT_BITMAP);
138
139 // Tell Led about the kinds of embeddings we will allow
140 EmbeddedObjectCreatorRegistry::Get ().AddStandardTypes ();
141 }
142 return bInit;
143}
144
145int ActiveLedItApp::ExitInstance ()
146{
147// Detect SPR#1599 a little earlier. Basic trouble with this bug is that the
148// ActiveX control objects don't get destroyed - and even though the CanUnloadDLL function
149// returns false - UnloadDLL is called anyhow - and this is called indirectly.
150// Must find some bugfix or better bug workaround eventually. -- LGP 2003-12-16
151#if qKeepListOfALInstancesForSPR_1599BWA
152 while (not ActiveLedItControl::GetAll ().empty ()) {
153 ActiveLedItControl* p = *ActiveLedItControl::GetAll ().begin ();
154 IUnknown* pi = p->GetControllingUnknown ();
155 while (pi->Release () > 0)
156 ;
157 }
158#endif
159 [[maybe_unused]] _AFX_THREAD_STATE* pState = AfxGetThreadState ();
160 ASSERT (pState != NULL);
161 Assert (pState->m_nCtrlRef == 0);
162 Assert (AfxGetModuleState ()->m_nObjectCount == 0);
163
164 return inherited::ExitInstance ();
165}
166
167/*
168 ********************************************************************************
169 ******************************** DllRegisterServer *****************************
170 ********************************************************************************
171 */
172STDAPI DllRegisterServer ()
173{
174 AFX_MANAGE_STATE (_afxModuleAddrThis);
175
176 if (!AfxOleRegisterTypeLib (AfxGetInstanceHandle (), _tlid))
177 return ResultFromScode (SELFREG_E_TYPELIB);
178
179 if (!COleObjectFactoryEx::UpdateRegistryAll (TRUE))
180 return ResultFromScode (SELFREG_E_CLASS);
181
182 // Mark the control as safe for initializing.
183 HRESULT hr = CreateComponentCategory (CATID_SafeForInitializing, L"Controls safely initializable from persistent data!");
184 if (FAILED (hr))
185 return hr;
186
187 hr = RegisterCLSIDInCategory (CLSID_ActiveLedIt, CATID_SafeForInitializing);
188 if (FAILED (hr))
189 return hr;
190
191 // Mark the control as safe for scripting.
192 hr = CreateComponentCategory (CATID_SafeForScripting, L"Controls safely scriptable!");
193 if (FAILED (hr))
194 return hr;
195
196 hr = RegisterCLSIDInCategory (CLSID_ActiveLedIt, CATID_SafeForScripting);
197 if (FAILED (hr))
198 return hr;
199
200 return NOERROR;
201}
202
203/*
204 ********************************************************************************
205 ******************************** DllUnregisterServer ***************************
206 ********************************************************************************
207 */
208// Removes entries from the system registry
209STDAPI DllUnregisterServer ()
210{
211 AFX_MANAGE_STATE (_afxModuleAddrThis);
212
213 // Remove entries from the registry.
214 HRESULT hr = UnRegisterCLSIDInCategory (CLSID_ActiveLedIt, CATID_SafeForInitializing);
215 if (FAILED (hr))
216 return hr;
217
218 hr = UnRegisterCLSIDInCategory (CLSID_ActiveLedIt, CATID_SafeForScripting);
219 if (FAILED (hr))
220 return hr;
221
222 if (!AfxOleUnregisterTypeLib (_tlid, _wVerMajor, _wVerMinor))
223 return ResultFromScode (SELFREG_E_TYPELIB);
224
225 if (!COleObjectFactoryEx::UpdateRegistryAll (FALSE))
226 return ResultFromScode (SELFREG_E_CLASS);
227
228 return NOERROR;
229}
#define AssertNotNull(p)
Definition Assertions.h:333
#define EnsureNotNull(p)
Definition Assertions.h:340