WinStd Additional templates and function helpers for Microsoft Windows using Standard C++ classes

COM.h
1/*
2 SPDX-License-Identifier: MIT
3 Copyright © 1991-2022 Amebis
4 Copyright © 2016 GÉANT
5*/
6
7#pragma once
8
9#include "Common.h"
10#include <unknwn.h>
11#include <string>
12
13 namespace winstd
14{
17
23 class com_runtime_error : public num_runtime_error<HRESULT>
24 {
25 public:
32 com_runtime_error(_In_ error_type num, _In_ const std::string& msg) : num_runtime_error<HRESULT>(num, msg)
33 {
34 }
35
42 com_runtime_error(_In_ error_type num, _In_opt_z_ const char *msg = nullptr) : num_runtime_error<HRESULT>(num, msg)
43 {
44 }
45 };
46
48
54
58 struct CoTaskMemFree_delete
59 {
63 CoTaskMemFree_delete() noexcept {}
64
70 template <class _T>
71 void operator()(_T *_Ptr) const
72 {
73 CoTaskMemFree(_Ptr);
74 }
75 };
76
80 template <class T>
81 class com_obj : public dplhandle<T*, NULL>
82 {
83 WINSTD_DPLHANDLE_IMPL(com_obj, NULL)
84
85 public:
91 com_obj(_In_ REFCLSID rclsid, _In_opt_ LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)
92 {
93 CoCreateInstance(rclsid, pUnkOuter, dwClsContext, __uuidof(T), (LPVOID*)&m_h);
94 }
95
101 template <class _Other>
102 com_obj(_In_ _Other *other)
103 {
104 assert(other);
105 other->QueryInterface(__uuidof(T), (void**)&m_h);
106 }
107
113 template <class _Other>
114 com_obj(_In_ com_obj<_Other> &other)
115 {
116 other->QueryInterface(__uuidof(T), (void**)&m_h);
117 }
118
122 virtual ~com_obj()
123 {
124 if (m_h != invalid)
125 free_internal();
126 }
127
133 HRESULT create(_In_ REFCLSID rclsid, _In_opt_ LPUNKNOWN pUnkOuter = NULL, _In_ DWORD dwClsContext = CLSCTX_ALL)
134 {
135 handle_type h;
136 HRESULT hr = CoCreateInstance(rclsid, pUnkOuter, dwClsContext, __uuidof(T), (void**)&h);
137 if (SUCCEEDED(hr))
138 attach(h);
139 return hr;
140 }
141
147 template <class _Other>
148 HRESULT query_interface(_Out_ _Other **h) const
149 {
150 assert(h);
151 assert(m_h);
152 return m_h->QueryInterface(__uuidof(_Other), (void**)h);
153 }
154
160 template <class _Other>
161 HRESULT query_interface(_Out_ com_obj<_Other> &h) const
162 {
163 assert(m_h);
164 _Other *_h;
165 HRESULT hr = m_h->QueryInterface(__uuidof(_Other), (void**)&_h);
166 if (SUCCEEDED(hr))
167 h.attach(_h);
168 return hr;
169 }
170
171 protected:
177 void free_internal() noexcept override
178 {
179 m_h->Release();
180 }
181
191 handle_type duplicate_internal(_In_ handle_type h) const noexcept override
192 {
193 h->AddRef();
194 return h;
195 }
196 };
197
201 class bstr : public dplhandle<BSTR, NULL>
202 {
203 WINSTD_DPLHANDLE_IMPL(bstr, NULL)
204
205 public:
209 bstr(_In_ LPCOLESTR src) noexcept
210 {
211 m_h = SysAllocString(src);
212 }
213
217 bstr(_In_ LPCOLESTR src, _In_ UINT len) noexcept
218 {
219 m_h = SysAllocStringLen(src, len);
220 }
221
225 template<class _Traits, class _Ax>
226 bstr(_In_ const std::basic_string<wchar_t, _Traits, _Ax> &src) noexcept
227 {
228 m_h = SysAllocStringLen(src.c_str(), (UINT)src.length());
229 }
230
236 virtual ~bstr()
237 {
238 if (m_h != invalid)
239 free_internal();
240 }
241
247 UINT length() const noexcept
248 {
249 return SysStringLen(m_h);
250 }
251
252 protected:
258 void free_internal() noexcept override
259 {
260 SysFreeString(m_h);
261 }
262
272 handle_type duplicate_internal(_In_ handle_type h) const noexcept override
273 {
274 return SysAllocStringLen(h, SysStringLen(h));
275 }
276 };
277
281 #pragma warning(push)
282 #pragma warning(disable: 26432) // Copy constructor and assignment operator are also present, but not detected by code analysis as they are using base type source object reference.
283 class variant : public VARIANT
284 {
285 public:
289 variant() noexcept
290 {
291 VariantInit(this);
292 }
293
297 variant(_In_ const VARIANT& varSrc)
298 {
299 vt = VT_EMPTY;
300 const HRESULT hr = VariantCopy(this, &varSrc);
301 if (FAILED(hr))
302 throw winstd::com_runtime_error(hr, "VariantCopy failed.");
303 }
304
308 #pragma warning(suppress: 26495) // vt member is initialized as a result of memcpy()
309 variant(_Inout_ VARIANT&& varSrc) noexcept
310 {
311 memcpy(this, &varSrc, sizeof(VARIANT));
312 varSrc.vt = VT_EMPTY;
313 }
314
318 variant(_In_ bool bSrc) noexcept
319 {
320 vt = VT_BOOL;
321 boolVal = bSrc ? VARIANT_TRUE : VARIANT_FALSE;
322 }
323
327 variant(_In_ char cSrc) noexcept
328 {
329 vt = VT_I1;
330 cVal = cSrc;
331 }
332
336 variant(_In_ unsigned char nSrc) noexcept
337 {
338 vt = VT_UI1;
339 bVal = nSrc;
340 }
341
345 variant(_In_ short nSrc) noexcept
346 {
347 vt = VT_I2;
348 iVal = nSrc;
349 }
350
354 variant(_In_ unsigned short nSrc) noexcept
355 {
356 vt = VT_UI2;
357 uiVal = nSrc;
358 }
359
363 variant(_In_ int nSrc, _In_ VARTYPE vtSrc = VT_I4) noexcept
364 {
365 assert(vtSrc == VT_I4 || vtSrc == VT_INT);
366 vt = vtSrc;
367 intVal = nSrc;
368 }
369
373 variant(_In_ unsigned int nSrc, _In_ VARTYPE vtSrc = VT_UI4) noexcept
374 {
375 assert(vtSrc == VT_UI4 || vtSrc == VT_UINT);
376 vt = vtSrc;
377 uintVal= nSrc;
378 }
379
383 variant(_In_ long nSrc, _In_ VARTYPE vtSrc = VT_I4) noexcept
384 {
385 assert(vtSrc == VT_I4 || vtSrc == VT_ERROR);
386 vt = vtSrc;
387 lVal = nSrc;
388 }
389
393 variant(_In_ unsigned long nSrc) noexcept
394 {
395 vt = VT_UI4;
396 ulVal = nSrc;
397 }
398
402 variant(_In_ float fltSrc) noexcept
403 {
404 vt = VT_R4;
405 fltVal = fltSrc;
406 }
407
411 variant(_In_ double dblSrc, _In_ VARTYPE vtSrc = VT_R8) noexcept
412 {
413 assert(vtSrc == VT_R8 || vtSrc == VT_DATE);
414 vt = vtSrc;
415 dblVal = dblSrc;
416 }
417
421 variant(_In_ long long nSrc) noexcept
422 {
423 vt = VT_I8;
424 llVal = nSrc;
425 }
426
430 variant(_In_ unsigned long long nSrc) noexcept
431 {
432 vt = VT_UI8;
433 ullVal = nSrc;
434 }
435
439 variant(_In_ CY cySrc) noexcept
440 {
441 vt = VT_CY;
442 cyVal.Hi = cySrc.Hi;
443 cyVal.Lo = cySrc.Lo;
444 }
445
449 variant(_In_z_ LPCOLESTR lpszSrc) noexcept
450 {
451 vt = VT_EMPTY;
452 *this = lpszSrc;
453 }
454
458 variant(_In_z_ BSTR bstr) noexcept
459 {
460 vt = VT_EMPTY;
461 *this = bstr;
462 }
463
467 variant(_In_opt_ IDispatch* pSrc)
468 {
469 vt = VT_DISPATCH;
470 pdispVal = pSrc;
471
472 if (pdispVal != NULL)
473 pdispVal->AddRef();
474 }
475
479 variant(_In_opt_ IUnknown* pSrc)
480 {
481 vt = VT_UNKNOWN;
482 punkVal = pSrc;
483
484 if (punkVal != NULL)
485 punkVal->AddRef();
486 }
487
491 variant(_In_ const SAFEARRAY *pSrc)
492 {
493 assert(pSrc != NULL);
494
495 LPSAFEARRAY pCopy;
496 const HRESULT hr = SafeArrayCopy(const_cast<LPSAFEARRAY>(pSrc), &pCopy);
497 if (FAILED(hr))
498 throw winstd::com_runtime_error(hr, "SafeArrayCopy failed.");
499
500 SafeArrayGetVartype(const_cast<LPSAFEARRAY>(pSrc), &vt);
501 vt |= VT_ARRAY;
502 parray = pCopy;
503 }
504
508 virtual ~variant()
509 {
510 VariantClear(this);
511 }
512
516 variant& operator=(_In_ const VARIANT& varSrc)
517 {
518 if (this != &varSrc) {
519 const HRESULT hr = VariantCopy(this, &varSrc);
520 if (FAILED(hr))
521 throw winstd::com_runtime_error(hr, "VariantCopy failed.");
522 }
523 return *this;
524 }
525
529 variant& operator=(_Inout_ VARIANT&& varSrc) noexcept
530 {
531 if (this != &varSrc) {
532 VariantClear(this);
533 memcpy(this, &varSrc, sizeof(VARIANT));
534 varSrc.vt = VT_EMPTY;
535 }
536 return *this;
537 }
538
542 variant& operator=(_In_ bool bSrc) noexcept
543 {
544 if (vt != VT_BOOL) {
545 VariantClear(this);
546 vt = VT_BOOL;
547 }
548 boolVal = bSrc ? VARIANT_TRUE : VARIANT_FALSE;
549 return *this;
550 }
551
555 variant& operator=(_In_ char cSrc) noexcept
556 {
557 if (vt != VT_I1) {
558 VariantClear(this);
559 vt = VT_I1;
560 }
561 cVal = cSrc;
562 return *this;
563 }
564
568 variant& operator=(_In_ unsigned char nSrc) noexcept
569 {
570 if (vt != VT_UI1) {
571 VariantClear(this);
572 vt = VT_UI1;
573 }
574 bVal = nSrc;
575 return *this;
576 }
577
581 variant& operator=(_In_ short nSrc) noexcept
582 {
583 if (vt != VT_I2) {
584 VariantClear(this);
585 vt = VT_I2;
586 }
587 iVal = nSrc;
588 return *this;
589 }
590
594 variant& operator=(_In_ unsigned short nSrc) noexcept
595 {
596 if (vt != VT_UI2) {
597 VariantClear(this);
598 vt = VT_UI2;
599 }
600 uiVal = nSrc;
601 return *this;
602 }
603
607 variant& operator=(_In_ int nSrc) noexcept
608 {
609 if (vt != VT_I4) {
610 VariantClear(this);
611 vt = VT_I4;
612 }
613 intVal = nSrc;
614 return *this;
615 }
616
620 variant& operator=(_In_ unsigned int nSrc) noexcept
621 {
622 if (vt != VT_UI4) {
623 VariantClear(this);
624 vt = VT_UI4;
625 }
626 uintVal= nSrc;
627 return *this;
628 }
629
633 variant& operator=(_In_ long nSrc) noexcept
634 {
635 if (vt != VT_I4) {
636 VariantClear(this);
637 vt = VT_I4;
638 }
639 lVal = nSrc;
640 return *this;
641 }
642
646 variant& operator=(_In_ unsigned long nSrc) noexcept
647 {
648 if (vt != VT_UI4) {
649 VariantClear(this);
650 vt = VT_UI4;
651 }
652 ulVal = nSrc;
653 return *this;
654 }
655
659 variant& operator=(_In_ long long nSrc) noexcept
660 {
661 if (vt != VT_I8) {
662 VariantClear(this);
663 vt = VT_I8;
664 }
665 llVal = nSrc;
666 return *this;
667 }
668
672 variant& operator=(_In_ unsigned long long nSrc) noexcept
673 {
674 if (vt != VT_UI8) {
675 VariantClear(this);
676 vt = VT_UI8;
677 }
678 ullVal = nSrc;
679
680 return *this;
681 }
682
686 variant& operator=(_In_ float fltSrc) noexcept
687 {
688 if (vt != VT_R4) {
689 VariantClear(this);
690 vt = VT_R4;
691 }
692 fltVal = fltSrc;
693 return *this;
694 }
695
699 variant& operator=(_In_ double dblSrc) noexcept
700 {
701 if (vt != VT_R8) {
702 VariantClear(this);
703 vt = VT_R8;
704 }
705 dblVal = dblSrc;
706 return *this;
707 }
708
712 variant& operator=(_In_ CY cySrc) noexcept
713 {
714 if (vt != VT_CY) {
715 VariantClear(this);
716 vt = VT_CY;
717 }
718 cyVal.Hi = cySrc.Hi;
719 cyVal.Lo = cySrc.Lo;
720 return *this;
721 }
722
726 variant& operator=(_In_z_ LPCOLESTR lpszSrc) noexcept
727 {
728 VariantClear(this);
729 vt = VT_BSTR;
730 bstrVal = SysAllocString(lpszSrc);
731 return *this;
732 }
733
737 variant& operator=(_Inout_opt_ IDispatch* pSrc)
738 {
739 VariantClear(this);
740 vt = VT_DISPATCH;
741 pdispVal = pSrc;
742 if (pdispVal != NULL)
743 pdispVal->AddRef();
744 return *this;
745 }
746
750 variant& operator=(_Inout_opt_ IUnknown* pSrc)
751 {
752 VariantClear(this);
753 vt = VT_UNKNOWN;
754 punkVal = pSrc;
755 if (punkVal != NULL)
756 punkVal->AddRef();
757 return *this;
758 }
759
763 variant& operator=(_In_ unsigned char* pbSrc) noexcept
764 {
765 if (vt != (VT_UI1|VT_BYREF)) {
766 VariantClear(this);
767 vt = VT_UI1|VT_BYREF;
768 }
769 pbVal = pbSrc;
770 return *this;
771 }
772
776 variant& operator=(_In_ short* pnSrc) noexcept
777 {
778 if (vt != (VT_I2|VT_BYREF)) {
779 VariantClear(this);
780 vt = VT_I2|VT_BYREF;
781 }
782 piVal = pnSrc;
783 return *this;
784 }
785
789 variant& operator=(_In_ unsigned short* pnSrc) noexcept
790 {
791 if (vt != (VT_UI2|VT_BYREF)) {
792 VariantClear(this);
793 vt = VT_UI2|VT_BYREF;
794 }
795 puiVal = pnSrc;
796 return *this;
797 }
798
802 variant& operator=(_In_ int* pnSrc) noexcept
803 {
804 if (vt != (VT_I4|VT_BYREF)) {
805 VariantClear(this);
806 vt = VT_I4|VT_BYREF;
807 }
808 pintVal = pnSrc;
809 return *this;
810 }
811
815 variant& operator=(_In_ unsigned int* pnSrc) noexcept
816 {
817 if (vt != (VT_UI4|VT_BYREF)) {
818 VariantClear(this);
819 vt = VT_UI4|VT_BYREF;
820 }
821 puintVal = pnSrc;
822 return *this;
823 }
824
828 variant& operator=(_In_ long* pnSrc) noexcept
829 {
830 if (vt != (VT_I4|VT_BYREF)) {
831 VariantClear(this);
832 vt = VT_I4|VT_BYREF;
833 }
834 plVal = pnSrc;
835 return *this;
836 }
837
841 variant& operator=(_In_ unsigned long* pnSrc) noexcept
842 {
843 if (vt != (VT_UI4|VT_BYREF)) {
844 VariantClear(this);
845 vt = VT_UI4|VT_BYREF;
846 }
847 pulVal = pnSrc;
848 return *this;
849 }
850
854 variant& operator=(_In_ long long* pnSrc) noexcept
855 {
856 if (vt != (VT_I8|VT_BYREF)) {
857 VariantClear(this);
858 vt = VT_I8|VT_BYREF;
859 }
860 pllVal = pnSrc;
861 return *this;
862 }
863
867 variant& operator=(_In_ unsigned long long* pnSrc) noexcept
868 {
869 if (vt != (VT_UI8|VT_BYREF)) {
870 VariantClear(this);
871 vt = VT_UI8|VT_BYREF;
872 }
873 pullVal = pnSrc;
874 return *this;
875 }
876
880 variant& operator=(_In_ float* pfSrc) noexcept
881 {
882 if (vt != (VT_R4|VT_BYREF)) {
883 VariantClear(this);
884 vt = VT_R4|VT_BYREF;
885 }
886 pfltVal = pfSrc;
887 return *this;
888 }
889
893 variant& operator=(_In_ double* pfSrc) noexcept
894 {
895 if (vt != (VT_R8|VT_BYREF)) {
896 VariantClear(this);
897 vt = VT_R8|VT_BYREF;
898 }
899 pdblVal = pfSrc;
900 return *this;
901 }
902
906 variant& operator=(_In_ const SAFEARRAY *pSrc) noexcept
907 {
908 assert(pSrc != NULL);
909 VariantClear(this);
910
911 LPSAFEARRAY pCopy;
912 const HRESULT hr = SafeArrayCopy(const_cast<LPSAFEARRAY>(pSrc), &pCopy);
913 if (SUCCEEDED(hr)) {
914 SafeArrayGetVartype(const_cast<LPSAFEARRAY>(pSrc), &vt);
915 vt |= VT_ARRAY;
916 parray = pCopy;
917 } else
918 assert(0);
919
920 return *this;
921 }
922
923 public:
932 bool operator==(_In_ const VARIANT& varSrc) const noexcept
933 {
934 if (vt == VT_NULL && varSrc.vt == VT_NULL) return true;
935 if (vt != varSrc.vt) return false;
936 return compare(static_cast<const VARIANT&>(*this), varSrc, LOCALE_USER_DEFAULT, 0) == static_cast<HRESULT>(VARCMP_EQ);
937 }
938
947 bool operator!=(_In_ const VARIANT& varSrc) const noexcept
948 {
949 return !operator==(varSrc);
950 }
951
960 bool operator<(_In_ const VARIANT& varSrc) const noexcept
961 {
962 if (vt == VT_NULL && varSrc.vt == VT_NULL) return false;
963 return compare(static_cast<const VARIANT&>(*this), varSrc, LOCALE_USER_DEFAULT, 0)== static_cast<HRESULT>(VARCMP_LT);
964 }
965
974 bool operator>(_In_ const VARIANT& varSrc) const noexcept
975 {
976 if (vt == VT_NULL && varSrc.vt == VT_NULL) return false;
977 return compare(static_cast<const VARIANT&>(*this), varSrc, LOCALE_USER_DEFAULT, 0)== static_cast<HRESULT>(VARCMP_GT);
978 }
979
988 bool operator<=(_In_ const VARIANT& varSrc) const noexcept
989 {
990 return !operator>(varSrc);
991 }
992
1001 bool operator>=(_In_ const VARIANT& varSrc) const noexcept
1002 {
1003 return !operator<(varSrc);
1004 }
1005
1011 HRESULT change_type(_In_ VARTYPE _vt, _In_opt_ USHORT wFlags = 0) noexcept
1012 {
1013 return VariantChangeType(this, this, wFlags, _vt);
1014 }
1015
1016 private:
1018 HRESULT compare(_In_ const VARIANT &varLeft, _In_ const VARIANT &varRight, _In_ LCID lcid, _In_ ULONG dwFlags) const noexcept
1019 {
1020 switch(vt) {
1021 case VT_I1: return varLeft.cVal == varRight.cVal ? VARCMP_EQ : varLeft.cVal > varRight.cVal ? VARCMP_GT : VARCMP_LT;
1022 case VT_UI2: return varLeft.uiVal == varRight.uiVal ? VARCMP_EQ : varLeft.uiVal > varRight.uiVal ? VARCMP_GT : VARCMP_LT;
1023 case VT_UI4: return varLeft.uintVal == varRight.uintVal ? VARCMP_EQ : varLeft.uintVal > varRight.uintVal ? VARCMP_GT : VARCMP_LT;
1024 case VT_UI8: return varLeft.ullVal == varRight.ullVal ? VARCMP_EQ : varLeft.ullVal > varRight.ullVal ? VARCMP_GT : VARCMP_LT;
1025 default: return VarCmp(const_cast<LPVARIANT>(&varLeft), const_cast<LPVARIANT>(&varRight), lcid, dwFlags);
1026 }
1027 }
1029 };
1030 #pragma warning(pop)
1031
1035 class com_initializer
1036 {
1037 WINSTD_NONCOPYABLE(com_initializer)
1038 WINSTD_NONMOVABLE(com_initializer)
1039
1040 public:
1046 com_initializer(_In_opt_ LPVOID pvReserved) noexcept
1047 {
1048 m_result = CoInitialize(pvReserved);
1049 }
1050
1056 com_initializer(_In_opt_ LPVOID pvReserved, _In_ DWORD dwCoInit) noexcept
1057 {
1058 m_result = CoInitializeEx(pvReserved, dwCoInit);
1059 }
1060
1066 virtual ~com_initializer()
1067 {
1068 if (SUCCEEDED(m_result))
1069 CoUninitialize();
1070 }
1071
1077 HRESULT status() const noexcept
1078 {
1079 return m_result;
1080 }
1081
1082 protected:
1083 HRESULT m_result;
1084 };
1085
1087}
winstd::bstr
BSTR string wrapper.
Definition: COM.h:202
winstd::bstr::~bstr
virtual ~bstr()
Destroys the string.
Definition: COM.h:236
winstd::bstr::bstr
bstr(_In_ const std::basic_string< wchar_t, _Traits, _Ax > &src) noexcept
Constructs BSTR from std::basic_string.
Definition: COM.h:226
winstd::bstr::free_internal
void free_internal() noexcept override
Destroys the string.
Definition: COM.h:258
winstd::bstr::bstr
bstr(_In_ LPCOLESTR src) noexcept
Constructs BSTR from OLE string.
Definition: COM.h:209
winstd::bstr::length
UINT length() const noexcept
Returns the length of the string.
Definition: COM.h:247
winstd::bstr::duplicate_internal
handle_type duplicate_internal(_In_ handle_type h) const noexcept override
Duplicates the string.
Definition: COM.h:272
winstd::bstr::bstr
bstr(_In_ LPCOLESTR src, _In_ UINT len) noexcept
Constructs BSTR from OLE string with length.
Definition: COM.h:217
winstd::com_initializer
Context scope automatic COM (un)initialization.
Definition: COM.h:1036
winstd::com_initializer::com_initializer
com_initializer(_In_opt_ LPVOID pvReserved) noexcept
Initializes the COM library on the current thread and identifies the concurrency model as single-thre...
Definition: COM.h:1046
winstd::com_initializer::com_initializer
com_initializer(_In_opt_ LPVOID pvReserved, _In_ DWORD dwCoInit) noexcept
Initializes the COM library for use by the calling thread, sets the thread's concurrency model,...
Definition: COM.h:1056
winstd::com_initializer::status
HRESULT status() const noexcept
Return result of CoInitialize() call.
Definition: COM.h:1077
winstd::com_initializer::~com_initializer
virtual ~com_initializer()
Uninitializes COM.
Definition: COM.h:1066
winstd::com_initializer::m_result
HRESULT m_result
Result of CoInitialize call.
Definition: COM.h:1083
winstd::com_obj
COM object wrapper template.
Definition: COM.h:82
winstd::com_obj::free_internal
void free_internal() noexcept override
Releases the object by decrementing reference counter.
Definition: COM.h:177
winstd::com_obj::duplicate_internal
handle_type duplicate_internal(_In_ handle_type h) const noexcept override
Duplicates the object by incrementing the reference counter.
Definition: COM.h:191
winstd::com_obj::com_obj
com_obj(_In_ com_obj< _Other > &other)
Queries the object for another interface and creates new class with it.
Definition: COM.h:114
winstd::com_obj::com_obj
com_obj(_In_ _Other *other)
Queries the object for another interface and creates new class with it.
Definition: COM.h:102
winstd::com_obj::create
HRESULT create(_In_ REFCLSID rclsid, _In_opt_ LPUNKNOWN pUnkOuter=NULL, _In_ DWORD dwClsContext=CLSCTX_ALL)
Creates a new object.
Definition: COM.h:133
winstd::com_obj::~com_obj
virtual ~com_obj()
Releases object.
Definition: COM.h:122
winstd::com_obj::com_obj
com_obj(_In_ REFCLSID rclsid, _In_opt_ LPUNKNOWN pUnkOuter=NULL, DWORD dwClsContext=CLSCTX_ALL)
Constructs a new object and creates a new class with it.
Definition: COM.h:91
winstd::com_obj::query_interface
HRESULT query_interface(_Out_ _Other **h) const
Queries the object for another interface.
Definition: COM.h:148
winstd::com_obj::query_interface
HRESULT query_interface(_Out_ com_obj< _Other > &h) const
Queries the object for another interface.
Definition: COM.h:161
winstd::com_runtime_error
COM runtime error.
Definition: COM.h:24
winstd::com_runtime_error::com_runtime_error
com_runtime_error(_In_ error_type num, _In_opt_z_ const char *msg=nullptr)
Constructs an exception.
Definition: COM.h:42
winstd::com_runtime_error::com_runtime_error
com_runtime_error(_In_ error_type num, _In_ const std::string &msg)
Constructs an exception.
Definition: COM.h:32
winstd::dplhandle
Base abstract template class to support object handle keeping for objects that support handle duplica...
Definition: Common.h:844
winstd::handle< T *, INVAL >::handle_type
T * handle_type
Datatype of the object handle this template class handles.
Definition: Common.h:585
winstd::handle< T *, INVAL >::attach
void attach(_In_opt_ handle_type h) noexcept
Sets a new object handle for the class.
Definition: Common.h:794
winstd::handle< T *, INVAL >::m_h
handle_type m_h
Object handle.
Definition: Common.h:833
winstd::num_runtime_error
Numerical runtime error.
Definition: Common.h:981
winstd::num_runtime_error< HRESULT >::error_type
HRESULT error_type
Error number type.
Definition: Common.h:983
winstd::variant
VARIANT struct wrapper.
Definition: COM.h:284
winstd::variant::operator=
variant & operator=(_In_ double *pfSrc) noexcept
Copy from double reference.
Definition: COM.h:893
winstd::variant::operator=
variant & operator=(_In_ short *pnSrc) noexcept
Copy from short reference.
Definition: COM.h:776
winstd::variant::operator=
variant & operator=(_In_ short nSrc) noexcept
Copy from short value.
Definition: COM.h:581
winstd::variant::operator=
variant & operator=(_In_ unsigned long long nSrc) noexcept
Copy from unsigned long long value.
Definition: COM.h:672
winstd::variant::variant
variant(_In_opt_ IDispatch *pSrc)
Constructs VARIANT from IDispatch.
Definition: COM.h:467
winstd::variant::operator>=
bool operator>=(_In_ const VARIANT &varSrc) const noexcept
Is variant greater than or equal to?
Definition: COM.h:1001
winstd::variant::variant
variant(_In_z_ LPCOLESTR lpszSrc) noexcept
Constructs VARIANT from OLE string.
Definition: COM.h:449
winstd::variant::variant
variant(_In_ long long nSrc) noexcept
Constructs VARIANT from 64-bit integer.
Definition: COM.h:421
winstd::variant::operator=
variant & operator=(_In_ int *pnSrc) noexcept
Copy from int reference.
Definition: COM.h:802
winstd::variant::operator>
bool operator>(_In_ const VARIANT &varSrc) const noexcept
Is variant greater than?
Definition: COM.h:974
winstd::variant::operator=
variant & operator=(_In_ float fltSrc) noexcept
Copy from float value.
Definition: COM.h:686
winstd::variant::operator=
variant & operator=(_In_ unsigned short nSrc) noexcept
Copy from unsigned short value.
Definition: COM.h:594
winstd::variant::operator=
variant & operator=(_In_ char cSrc) noexcept
Copy from char value.
Definition: COM.h:555
winstd::variant::variant
variant(_In_ int nSrc, _In_ VARTYPE vtSrc=VT_I4) noexcept
Constructs VARIANT from integer.
Definition: COM.h:363
winstd::variant::operator=
variant & operator=(_In_ CY cySrc) noexcept
Copy from CY value.
Definition: COM.h:712
winstd::variant::operator=
variant & operator=(_In_ unsigned long long *pnSrc) noexcept
Copy from unsigned long long reference.
Definition: COM.h:867
winstd::variant::operator=
variant & operator=(_Inout_opt_ IDispatch *pSrc)
Copy from IDispatch.
Definition: COM.h:737
winstd::variant::variant
variant(_In_ unsigned char nSrc) noexcept
Constructs VARIANT from byte.
Definition: COM.h:336
winstd::variant::variant
variant(_In_ float fltSrc) noexcept
Constructs VARIANT from float.
Definition: COM.h:402
winstd::variant::variant
variant(_In_ unsigned long nSrc) noexcept
Constructs VARIANT from unsigned long.
Definition: COM.h:393
winstd::variant::variant
variant(_In_ double dblSrc, _In_ VARTYPE vtSrc=VT_R8) noexcept
Constructs VARIANT from double or variant date.
Definition: COM.h:411
winstd::variant::variant
variant(_In_ long nSrc, _In_ VARTYPE vtSrc=VT_I4) noexcept
Constructs VARIANT from long.
Definition: COM.h:383
winstd::variant::variant
variant(_In_ unsigned int nSrc, _In_ VARTYPE vtSrc=VT_UI4) noexcept
Constructs VARIANT from unsigned integer.
Definition: COM.h:373
winstd::variant::~variant
virtual ~variant()
Destroys VARIANT.
Definition: COM.h:508
winstd::variant::operator<
bool operator<(_In_ const VARIANT &varSrc) const noexcept
Is variant less than?
Definition: COM.h:960
winstd::variant::operator=
variant & operator=(_In_ unsigned long *pnSrc) noexcept
Copy from unsigned long reference.
Definition: COM.h:841
winstd::variant::operator=
variant & operator=(_In_ long nSrc) noexcept
Copy from long value.
Definition: COM.h:633
winstd::variant::operator=
variant & operator=(_In_ int nSrc) noexcept
Copy from int value.
Definition: COM.h:607
winstd::variant::operator=
variant & operator=(_Inout_opt_ IUnknown *pSrc)
Copy from IUnknown.
Definition: COM.h:750
winstd::variant::operator=
variant & operator=(_In_ long long nSrc) noexcept
Copy from long long value.
Definition: COM.h:659
winstd::variant::operator=
variant & operator=(_In_ const SAFEARRAY *pSrc) noexcept
Copy from SAFEARRAY.
Definition: COM.h:906
winstd::variant::operator!=
bool operator!=(_In_ const VARIANT &varSrc) const noexcept
Is variant not equal to?
Definition: COM.h:947
winstd::variant::variant
variant(_In_ short nSrc) noexcept
Constructs VARIANT from short.
Definition: COM.h:345
winstd::variant::variant
variant(_In_ unsigned short nSrc) noexcept
Constructs VARIANT from unsigned short.
Definition: COM.h:354
winstd::variant::variant
variant(_In_ unsigned long long nSrc) noexcept
Constructs VARIANT from unsigned integer.
Definition: COM.h:430
winstd::variant::operator==
bool operator==(_In_ const VARIANT &varSrc) const noexcept
Is variant equal to?
Definition: COM.h:932
winstd::variant::operator=
variant & operator=(_In_ unsigned char *pbSrc) noexcept
Copy from unsigned char reference.
Definition: COM.h:763
winstd::variant::variant
variant(_In_z_ BSTR bstr) noexcept
Constructs VARIANT from BSTR.
Definition: COM.h:458
winstd::variant::variant
variant() noexcept
Constructs blank VARIANT.
Definition: COM.h:289
winstd::variant::operator=
variant & operator=(_In_ double dblSrc) noexcept
Copy from double value.
Definition: COM.h:699
winstd::variant::operator=
variant & operator=(_In_ const VARIANT &varSrc)
Copy from another VARIANT.
Definition: COM.h:516
winstd::variant::change_type
HRESULT change_type(_In_ VARTYPE _vt, _In_opt_ USHORT wFlags=0) noexcept
Converts a variant from one type to another.
Definition: COM.h:1011
winstd::variant::operator=
variant & operator=(_In_ bool bSrc) noexcept
Copy from bool value.
Definition: COM.h:542
winstd::variant::operator<=
bool operator<=(_In_ const VARIANT &varSrc) const noexcept
Is variant less than or equal to?
Definition: COM.h:988
winstd::variant::operator=
variant & operator=(_In_ unsigned long nSrc) noexcept
Copy from unsigned long value.
Definition: COM.h:646
winstd::variant::operator=
variant & operator=(_In_ long long *pnSrc) noexcept
Copy from long long reference.
Definition: COM.h:854
winstd::variant::operator=
variant & operator=(_In_z_ LPCOLESTR lpszSrc) noexcept
Copy from OLE string value.
Definition: COM.h:726
winstd::variant::variant
variant(_In_ const VARIANT &varSrc)
Constructs VARIANT from another.
Definition: COM.h:297
winstd::variant::variant
variant(_Inout_ VARIANT &&varSrc) noexcept
Moves VARIANT from another.
Definition: COM.h:309
winstd::variant::variant
variant(_In_ char cSrc) noexcept
Constructs VARIANT from character.
Definition: COM.h:327
winstd::variant::variant
variant(_In_ CY cySrc) noexcept
Constructs VARIANT from CY (64-bit integer)
Definition: COM.h:439
winstd::variant::operator=
variant & operator=(_In_ unsigned char nSrc) noexcept
Copy from unsigned char value.
Definition: COM.h:568
winstd::variant::variant
variant(_In_opt_ IUnknown *pSrc)
Constructs VARIANT from IUnknown.
Definition: COM.h:479
winstd::variant::operator=
variant & operator=(_In_ unsigned int nSrc) noexcept
Copy from unsigned int value.
Definition: COM.h:620
winstd::variant::operator=
variant & operator=(_In_ float *pfSrc) noexcept
Copy from float reference.
Definition: COM.h:880
winstd::variant::operator=
variant & operator=(_Inout_ VARIANT &&varSrc) noexcept
Moves from another VARIANT.
Definition: COM.h:529
winstd::variant::variant
variant(_In_ bool bSrc) noexcept
Constructs VARIANT from bool.
Definition: COM.h:318
winstd::variant::variant
variant(_In_ const SAFEARRAY *pSrc)
Constructs VARIANT from SAFEARRAY.
Definition: COM.h:491
winstd::variant::operator=
variant & operator=(_In_ unsigned short *pnSrc) noexcept
Copy from unsigned short reference.
Definition: COM.h:789
winstd::variant::operator=
variant & operator=(_In_ long *pnSrc) noexcept
Copy from long reference.
Definition: COM.h:828
winstd::variant::operator=
variant & operator=(_In_ unsigned int *pnSrc) noexcept
Copy from unsigned int reference.
Definition: COM.h:815
WINSTD_NONCOPYABLE
#define WINSTD_NONCOPYABLE(C)
Declares a class as non-copyable.
Definition: Common.h:53
WINSTD_NONMOVABLE
#define WINSTD_NONMOVABLE(C)
Declares a class as non-movable.
Definition: Common.h:61
WINSTD_DPLHANDLE_IMPL
#define WINSTD_DPLHANDLE_IMPL(C, INVAL)
Implements default constructors and operators to prevent their auto-generation by compiler.
Definition: Common.h:150
winstd::handle< T *, INVAL >::invalid
static const T * invalid
Invalid handle value.
Definition: Common.h:590
winstd::CoTaskMemFree_delete
Deleter for unique_ptr using CoTaskMemFree.
Definition: COM.h:59
winstd::CoTaskMemFree_delete::operator()
void operator()(_T *_Ptr) const
Delete a pointer.
Definition: COM.h:71
winstd::CoTaskMemFree_delete::CoTaskMemFree_delete
CoTaskMemFree_delete() noexcept
Default constructor.
Definition: COM.h:63