summaryrefslogtreecommitdiffstats
path: root/source/core/platform.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/core/platform.cpp')
-rw-r--r--source/core/platform.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/source/core/platform.cpp b/source/core/platform.cpp
index d160fd37c..ff7d8e231 100644
--- a/source/core/platform.cpp
+++ b/source/core/platform.cpp
@@ -27,6 +27,39 @@ namespace Slang
#ifdef _WIN32
+// Make sure SlangResult match for common standard window HRESULT
+SLANG_COMPILE_TIME_ASSERT(E_FAIL == SLANG_FAIL);
+SLANG_COMPILE_TIME_ASSERT(E_NOINTERFACE == SLANG_E_NO_INTERFACE);
+SLANG_COMPILE_TIME_ASSERT(E_HANDLE == SLANG_E_INVALID_HANDLE);
+SLANG_COMPILE_TIME_ASSERT(E_NOTIMPL == SLANG_E_NOT_IMPLEMENTED);
+SLANG_COMPILE_TIME_ASSERT(E_INVALIDARG == SLANG_E_INVALID_ARG);
+SLANG_COMPILE_TIME_ASSERT(E_OUTOFMEMORY == SLANG_E_OUT_OF_MEMORY);
+
+/* static */SlangResult PlatformUtil::appendResult(SlangResult res, StringBuilder& builderOut)
+{
+ if (SLANG_FAILED(res) && res != SLANG_FAIL)
+ {
+ LPWSTR buffer = nullptr;
+ FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER,
+ nullptr,
+ res,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
+ (LPWSTR)&buffer,
+ 0,
+ nullptr);
+
+ if (buffer)
+ {
+ builderOut << " ";
+ // Convert to string
+ builderOut.Append(String::FromWString(buffer));
+ LocalFree(buffer);
+ return SLANG_OK;
+ }
+ }
+ return SLANG_FAIL;
+}
+
/* static */SlangResult SharedLibrary::loadWithPlatformFilename(char const* platformFileName, SharedLibrary::Handle& handleOut)
{
handleOut = nullptr;
@@ -78,6 +111,11 @@ namespace Slang
#else // _WIN32
+/* static */SlangResult PlatformUtil::appendResult(SlangResult res, StringBuilder& builderOut)
+{
+ return SLANG_E_NOT_IMPLEMENTED;
+}
+
/* static */SlangResult SharedLibrary::loadWithPlatformFilename(char const* platformFileName, Handle& handleOut)
{
handleOut = nullptr;