Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
ATL.h
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Frameworks_Led_Platform_ATL_h_
5#define _Stroika_Frameworks_Led_Platform_ATL_h_ 1
6
7/*
8@MODULE: Led_ATL
9@DESCRIPTION:
10 <p>Led MFC specific wrappers.</p>
11 <p>REALLY not yet implemented (and won't be for 3.1). But I do have some components using
12 ATL, and this is a temporary repository for those utilities.</p>
13 */
14
15#include "Stroika/Frameworks/StroikaPreComp.h"
16
17static_assert (qStroika_HasComponent_ATLMFC,
18 "Error: Stroika::Framework::Led::Platform ATL code requires the ATLMFC feature to be set true");
19
20#include <atlbase.h>
21#include <atlcom.h>
22
23#include "Stroika/Frameworks/Led/Config.h"
24#include "Stroika/Frameworks/Led/Support.h"
25
26namespace Stroika::Frameworks::Led::Platform {
27
28 /*
29 @CLASS: CComObjectWithARGS<BASE,CTOR_ARGS>
30 @DESCRIPTION: <p>Virtually identical to the ATL class @'CComObject<Base>', except that this is used
31 to allow an object to be directly constructed from C++ (instead of through CoCreateInstance), and
32 allowing constructor arguments to be passed along. It seems CRAZY that this isn't made
33 straight-forward in ATL. Perhaps it is - and I just haven't figured it out.
34 </p>
35 <p>This is functionally similar to the hack I used to do (e.g. at LEC) by patching
36 (replacing/cloning) the END_COM_MAP macro (to do the AddRef/etc method defs you see
37 here). I'm not sure which approach is better - but this isn't too bad. NB: this code is
38 based on the @'CComObject<Base>' code from _ATL_VER==0x0710 (from MSVC.Net 2003).
39 </p>
40 */
41 template <typename BASE, typename CTOR_ARGS>
42 class CComObjectWithARGS : public BASE {
43 private:
44 using inherited = BASE;
45
46 public:
47 CComObjectWithARGS (const CTOR_ARGS& args);
48 virtual ~CComObjectWithARGS () noexcept;
49
50 public:
51 STDMETHOD_ (ULONG, AddRef)
52 ();
53 STDMETHOD_ (ULONG, Release)
54 ();
55 STDMETHOD (QueryInterface)
56 (REFIID iid, void** ppvObject) noexcept;
57 };
58
59 /*
60 ********************************************************************************
61 ***************************** Implementation Details ***************************
62 ********************************************************************************
63 */
64 // class CComObjectWithARGS<BASE,CTOR_ARGS>
65 template <typename BASE, typename CTOR_ARGS>
66 inline CComObjectWithARGS<BASE, CTOR_ARGS>::CComObjectWithARGS (const CTOR_ARGS& args)
67 : inherited (args)
68 {
69 _pAtlModule->Lock ();
70 }
71 template <typename BASE, typename CTOR_ARGS>
72 CComObjectWithARGS<BASE, CTOR_ARGS>::~CComObjectWithARGS () noexcept
73 {
74 this->m_dwRef = -(LONG_MAX / 2);
75 this->FinalRelease ();
76#ifdef _ATL_DEBUG_INTERFACES
77 _AtlDebugInterfacesModule.DeleteNonAddRefThunk (_GetRawUnknown ());
78#endif
79 _pAtlModule->Unlock ();
80 }
81 template <typename BASE, typename CTOR_ARGS>
82 ULONG STDMETHODCALLTYPE CComObjectWithARGS<BASE, CTOR_ARGS>::AddRef ()
83 {
84 return this->InternalAddRef ();
85 }
86 template <typename BASE, typename CTOR_ARGS>
87 ULONG STDMETHODCALLTYPE CComObjectWithARGS<BASE, CTOR_ARGS>::Release ()
88 {
89 ULONG l = this->InternalRelease ();
90 if (l == 0) {
91 delete this;
92 }
93 return l;
94 }
95 template <typename BASE, typename CTOR_ARGS>
96 HRESULT STDMETHODCALLTYPE CComObjectWithARGS<BASE, CTOR_ARGS>::QueryInterface (REFIID iid, void** ppvObject) noexcept
97 {
98 //if _InternalQueryInterface is undefined then you forgot BEGIN_COM_MAP
99 return this->_InternalQueryInterface (iid, ppvObject);
100 }
101
102}
103
104#endif /*_Stroika_Frameworks_Led_Platform_ATL_h_*/