summaryrefslogtreecommitdiff
path: root/zen/com_util.h
diff options
context:
space:
mode:
authorDaniel Wilhelm <daniel@wili.li>2014-04-18 17:31:23 +0200
committerDaniel Wilhelm <daniel@wili.li>2014-04-18 17:31:23 +0200
commit851b6f99c1248c8ec8e33322a3179c1d82fdd515 (patch)
tree5b9abf4c4e648ea48ed4873e3c4bf1b225c64daf /zen/com_util.h
parent6.1 (diff)
downloadFreeFileSync-851b6f99c1248c8ec8e33322a3179c1d82fdd515.tar.gz
FreeFileSync-851b6f99c1248c8ec8e33322a3179c1d82fdd515.tar.bz2
FreeFileSync-851b6f99c1248c8ec8e33322a3179c1d82fdd515.zip
6.2
Diffstat (limited to 'zen/com_util.h')
-rw-r--r--zen/com_util.h121
1 files changed, 0 insertions, 121 deletions
diff --git a/zen/com_util.h b/zen/com_util.h
deleted file mode 100644
index 5189b48e..00000000
--- a/zen/com_util.h
+++ /dev/null
@@ -1,121 +0,0 @@
-// **************************************************************************
-// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl.html *
-// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved *
-// **************************************************************************
-
-#ifndef COM_UTILITY_HEADER
-#define COM_UTILITY_HEADER
-
-#include "com_ptr.h"
-#include <string>
-#include <cassert>
-
-namespace zen
-{
-//get an enumeration interface as a std::vector of bound(!) ComPtr(s)
-template <class T, class U>
-std::vector<ComPtr<T>> convertEnum(const ComPtr<U>& enumObj); //enumObj: must have the "_NewEnum" property that supports the IEnumUnknown interface
-
-/*
-extract text from com object member function returning a single BSTR: HRESULT ComInterface::MemFun([out] BSTR *pbstr);
- Example: ComPtr<...> comObj =...;
- std::wstring description = getText(comObj, &IUPnPDevice::get_Description);
-*/
-template <class T, class MemFun>
-std::wstring getText(ComPtr<T> comObj, MemFun memFun);
-
-
-//RAII class handling BSTR
-class Bstring
-{
-public:
- Bstring(const std::wstring& str) { str_ = ::SysAllocStringLen(str.data(), str.length()); } //string::data() returns unmodified string potentially containing 0-values
- ~Bstring() { if (str_) ::SysFreeString(str_); }
-
- const BSTR get() const { return str_; }
-
-private:
- Bstring(const Bstring&); //not implemented
- Bstring& operator=(const Bstring&); //
-
- BSTR str_;
-};
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-//############################ inline implemenatation ##################################
-template <class T, class U> inline
-std::vector<ComPtr<T>> convertEnum(const ComPtr<U>& enumObj)
-{
- std::vector<ComPtr<T>> output;
-
- if (enumObj)
- {
- ComPtr<IUnknown> unknown;
- enumObj->get__NewEnum(unknown.init());
- ComPtr<IEnumUnknown> enumUnknown = com_dynamic_cast<IEnumUnknown>(unknown);
-
- assert(enumUnknown); //IEnumUnknown must be supported!
- if (enumUnknown)
- {
- ComPtr<IUnknown> itemTmp;
- while (enumUnknown->Next(1, itemTmp.init(), nullptr) == S_OK) //returns S_FALSE == 1 when finished! Don't use SUCCEEDED()!!!
- {
- ComPtr<T> itemNew = com_dynamic_cast<T>(itemTmp);
- if (itemNew)
- output.push_back(itemNew);
- }
- }
- }
-
- return output;
-}
-
-
-template <class T, class MemFun> inline
-std::wstring getText(ComPtr<T> comObj, MemFun memFun)
-{
- std::wstring text;
- {
- if (!comObj)
- return std::wstring();
-
- BSTR bstr = nullptr;
- if (FAILED((comObj.get()->*memFun)(&bstr)))
- return std::wstring();
-
- if (bstr) //nullptr means "no text"
- {
- text = std::wstring(bstr, ::SysStringLen(bstr)); //correctly copy 0-characters
- ::SysFreeString(bstr);
- }
- }
- return text;
-}
-}
-
-
-#endif //COM_UTILITY_HEADER
bgstack15