aboutsummaryrefslogtreecommitdiff
path: root/src/zencore/windows.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2023-05-15 17:58:46 +0200
committerGitHub <[email protected]>2023-05-15 17:58:46 +0200
commit121d3fb3d9835ec78a1de7f268e79bf79cbf5865 (patch)
tree2f9c9f5c6a1d3ed41a9f3009104002bc5dd94bb8 /src/zencore/windows.cpp
parentall threads should be named (#304) (diff)
downloadzen-121d3fb3d9835ec78a1de7f268e79bf79cbf5865.tar.xz
zen-121d3fb3d9835ec78a1de7f268e79bf79cbf5865.zip
Remove ATL header usage (#306)
ATL has been used here and there as a convenience. Given that this is a legacy component and not always something which gets installed along with the compiler we hereby remove the dependency altogether in favour of our own simple wrappers
Diffstat (limited to 'src/zencore/windows.cpp')
-rw-r--r--src/zencore/windows.cpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/zencore/windows.cpp b/src/zencore/windows.cpp
new file mode 100644
index 000000000..76d8ab445
--- /dev/null
+++ b/src/zencore/windows.cpp
@@ -0,0 +1,64 @@
+
+// Copyright Epic Games, Inc. All Rights Reserved.
+
+#include "zencore/zencore.h"
+
+#if ZEN_PLATFORM_WINDOWS
+# include <zencore/except.h>
+# include "zencore/windows.h"
+
+namespace zen::windows {
+
+FileMapping::FileMapping(_In_ FileMapping& orig)
+{
+ m_pData = NULL;
+ m_hMapping = NULL;
+
+ HRESULT hr = CopyFrom(orig);
+ if (FAILED(hr))
+ zen::ThrowSystemException(hr, "Failed to clone FileMapping");
+}
+
+FileMapping&
+FileMapping::operator=(_In_ FileMapping& orig)
+{
+ HRESULT hr = CopyFrom(orig);
+ if (FAILED(hr))
+ zen::ThrowSystemException(hr, "Failed to clone FileMapping");
+
+ return *this;
+}
+
+HRESULT
+FileMapping::CopyFrom(_In_ FileMapping& orig) throw()
+{
+ if (this == &orig)
+ return S_OK;
+
+ ZEN_ASSERT(m_pData == NULL);
+ ZEN_ASSERT(m_hMapping == NULL);
+ ZEN_ASSERT(orig.m_pData != NULL);
+
+ m_dwViewDesiredAccess = orig.m_dwViewDesiredAccess;
+ m_nOffset.QuadPart = orig.m_nOffset.QuadPart;
+ m_nMappingSize = orig.m_nMappingSize;
+
+ if (!::DuplicateHandle(GetCurrentProcess(), orig.m_hMapping, GetCurrentProcess(), &m_hMapping, NULL, TRUE, DUPLICATE_SAME_ACCESS))
+ return MapHresultFromLastError();
+
+ m_pData = ::MapViewOfFileEx(m_hMapping, m_dwViewDesiredAccess, m_nOffset.HighPart, m_nOffset.LowPart, m_nMappingSize, NULL);
+ if (m_pData == NULL)
+ {
+ HRESULT hr;
+
+ hr = MapHresultFromLastError();
+ ::CloseHandle(m_hMapping);
+ m_hMapping = NULL;
+ return hr;
+ }
+
+ return S_OK;
+}
+
+} // namespace zen::windows
+#endif