diff options
Diffstat (limited to 'source/core')
| -rw-r--r-- | source/core/platform.cpp | 38 | ||||
| -rw-r--r-- | source/core/platform.h | 9 |
2 files changed, 47 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; diff --git a/source/core/platform.h b/source/core/platform.h index a545d139d..544ae8c16 100644 --- a/source/core/platform.h +++ b/source/core/platform.h @@ -47,6 +47,15 @@ namespace Slang SharedLibrary(); }; + struct PlatformUtil + { + /// Appends a text interpretation of a result (as defined by supporting OS) + /// @param res Result to produce a string for + /// @param builderOut Append the string produced to builderOut + /// @return SLANG_OK if string is found and appended. Fail otherwise. SLANG_E_NOT_IMPLEMENTED if there is no impl for this platform. + static SlangResult appendResult(SlangResult res, StringBuilder& builderOut); + }; + #ifndef _MSC_VER #define _fileno fileno #define _isatty isatty |
