Skip to content

Commit

Permalink
Merge pull request #24 from fredemmott/cpp20
Browse files Browse the repository at this point in the history
C++20? C++20.
  • Loading branch information
nefarius authored Oct 12, 2023
2 parents 5b38e18 + 5fd42c9 commit 68083f3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Injector/Injector.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@
<DebugInformationFormat>
</DebugInformationFormat>
<EnablePREfast>false</EnablePREfast>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
<Link>
<AdditionalDependencies>DbgHelp.lib;shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
Expand Down Expand Up @@ -283,6 +284,7 @@
<WarningLevel>Level4</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<EnablePREfast>false</EnablePREfast>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
<Link>
<AdditionalDependencies>DbgHelp.lib;shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
Expand Down
12 changes: 10 additions & 2 deletions Injector/StringUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ S_type toLower(const S_type& in)
}

inline std::wstring utf8_to_wstr(const std::string& utf8) {
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> wcu8;
return wcu8.from_bytes(utf8);
const auto wideCharCount = MultiByteToWideChar(CP_UTF8, 0, utf8.data(), utf8.size(), nullptr, 0);
std::wstring wstr;
wstr.resize(wideCharCount);

// While the docs say the return value includes trailing null, this is only the case if the
// input has a trailing null, and if we include it in the size parameter.
//
// utf8.size() excludes the trailing null, so the wstring does too
MultiByteToWideChar(CP_UTF8, 0, utf8.data(), utf8.size(), wstr.data(), wideCharCount);
return wstr;
}

0 comments on commit 68083f3

Please sign in to comment.