diff --git a/cppwinrt/main.cpp b/cppwinrt/main.cpp index b46e08f58..c0a2721cd 100644 --- a/cppwinrt/main.cpp +++ b/cppwinrt/main.cpp @@ -8,6 +8,7 @@ #include "component_writers.h" #include "file_writers.h" #include "type_writers.h" +#include namespace cppwinrt { @@ -374,5 +375,7 @@ Where is one or more of: int main(int const argc, char** argv) { + // Dynamically enable long path support + ((unsigned char*)(NtCurrentTeb()->ProcessEnvironmentBlock))[3] |= 0x80; return cppwinrt::run(argc, argv); } diff --git a/cppwinrt/text_writer.h b/cppwinrt/text_writer.h index 5045b9395..bde87806e 100644 --- a/cppwinrt/text_writer.h +++ b/cppwinrt/text_writer.h @@ -157,9 +157,18 @@ namespace cppwinrt { if (!file_equal(filename)) { - std::ofstream file{ filename, std::ios::out | std::ios::binary }; - file.write(m_first.data(), m_first.size()); - file.write(m_second.data(), m_second.size()); + std::ofstream file; + file.exceptions(std::ofstream::failbit | std::ofstream::badbit); + try + { + file.open(filename, std::ios::out | std::ios::binary); + file.write(m_first.data(), m_first.size()); + file.write(m_second.data(), m_second.size()); + } + catch (std::ofstream::failure const& e) + { + throw std::filesystem::filesystem_error(e.what(), filename, std::io_errc::stream); + } } m_first.clear(); m_second.clear();