---
 .../include/wrl/wrappers/corewrappers.h            | 83
+++++++++++++++++++++-
 1 file changed, 82 insertions(+), 1 deletion(-)


diff --git a/mingw-w64-headers/include/wrl/wrappers/corewrappers.h b/mingw-w64-headers/include/wrl/wrappers/corewrappers.h
index e63d5e9..6a3e873 100644
--- a/mingw-w64-headers/include/wrl/wrappers/corewrappers.h
+++ b/mingw-w64-headers/include/wrl/wrappers/corewrappers.h
@@ -8,11 +8,92 @@
 #define _WRL_COREWRAPPERS_H_
 
 #include <windows.h>
-/* #include <intsafe.h> */
+#include <intsafe.h>
 #include <winstring.h>
 #include <roapi.h>
 
 /* #include <wrl/def.h> */
 #include <wrl/internal.h>
 
+namespace Microsoft {
+    namespace WRL {
+        namespace Details {
+            struct Dummy {};
+        }
+
+        namespace Wrappers {
+            class HStringReference {
+            private:
+                void Init(const wchar_t* str, unsigned int len) {
+                    HRESULT hres = ::WindowsCreateStringReference(str, len, &header_, &hstr_);
+                    if (FAILED(hres))
+                        ::Microsoft::WRL::Details::RaiseException(hres);
+                }
+
+                HStringReference() : hstr_(nullptr) {}
+
+            public:
+                HStringReference(const wchar_t* str, unsigned int len) throw() : hstr_(nullptr) {
+                    Init(str, len);
+                }
+
+                template<unsigned int sizeDest>
+                 explicit HStringReference(wchar_t const (&str)[sizeDest]) throw() : hstr_(nullptr) {
+                    Init(str, sizeDest - 1);
+                }
+
+                template <size_t sizeDest>
+                explicit HStringReference(wchar_t (&strRef)[sizeDest]) throw() {
+                    const wchar_t *str = static_cast<const wchar_t*>(strRef);
+                    Init(str, ::wcslen(str));
+                }
+
+                template<typename T>
+                explicit HStringReference(const T &strRef) throw() : hstr_(nullptr) {
+                    const wchar_t* str = static_cast<const wchar_t*>(strRef);
+                    size_t len = ::wcslen(str);
+                    if(static_cast<size_t>(static_cast<unsigned int>(len)) != len)
+                        ::Microsoft::WRL::Details::RaiseException(INTSAFE_E_ARITHMETIC_OVERFLOW);
+                    Init(str, len);
+                }
+
+                HStringReference(const HStringReference &other) throw() : hstr_(nullptr) {
+                    unsigned int len = 0;
+                    const wchar_t* value = other.GetRawBuffer(&len);
+                    Init(value, len);
+                }
+
+                ~HStringReference() throw() {
+                    hstr_ = nullptr;
+                }
+
+                HStringReference& operator=(const HStringReference &other) throw() {
+                    unsigned int length = 0;
+                    const wchar_t* value = other.GetRawBuffer(&length);
+                    Init(value, length);
+                    return *this;
+                }
+
+                HSTRING Get() const throw() {
+                    return hstr_;
+                }
+
+                const wchar_t *GetRawBuffer(unsigned int *length) const {
+                    return ::WindowsGetStringRawBuffer(hstr_, length);
+                }
+
+                HRESULT CopyTo(HSTRING *str) const throw() {
+                    return ::WindowsDuplicateString(hstr_, str);
+                }
+
+                friend class HString;
+
+            protected:
+                HSTRING_HEADER header_;
+                HSTRING hstr_;
+            };
+        }
+    }
+}
+
 #endif

------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to