Skip to content

Commit 0a7cfc4

Browse files
ejaquayejaquay
authored andcommitted
Set project to C++17
vcc-base.props set to C++17 core/utils/winapi.cpp modified to demonstrate C++17 namespace nesting and to fix STL4017. Still don't like the winapi.cpp filename but that perhaps is for another commit.
1 parent 5f2aa81 commit 0a7cfc4

File tree

3 files changed

+31
-14
lines changed

3 files changed

+31
-14
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ VCC is written in C++ and Microsoft Visual Studio 2022 Community is used to buil
2828

2929
To build VCC from the command line, launch the "Developer Command Prompt for VS 2022". From there, change to the directory containing the VCC sources and type "Build" or "BuildClean".
3030

31-
Within Visual Studio, the "Release" and "Debug" configurations build VCC binaries that will run on current Windows versions. The "Legacy" configuration builds binaries that will run on Windows XP. "Legacy" uses the v121_xp build tools from which you need to find and install. Maintaining a VCC version that will run on XP is becoming difficult and it is likely a future version will no longer support it
31+
Within Visual Studio, the "Release" and "Debug" configurations build VCC binaries that will run on current Windows versions. The "Legacy" configuration builds binaries that will run on Windows XP. "Legacy" uses the v141_xp build tools from which you need to find and install. Maintaining a VCC version that will run on XP is becoming difficult and it is likely a future version will no longer support it.
32+
33+
Portions of VCC code have been modified to use features of the C++17 standard.
3234

3335
## Contributing to VCC
3436
We welcome patches and code contributions that are consistent with our goals. Please comment your code well and add your name if you want credit for your work.

libcommon/src/core/utils/winapi.cpp

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,36 @@
1515
// You should have received a copy of the GNU General Public License along with
1616
// VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
1717
////////////////////////////////////////////////////////////////////////////////
18-
#include <vcc/core/utils/winapi.h>
19-
#include <codecvt>
2018

19+
#include <vcc/core/utils/winapi.h>
20+
#include <string>
21+
#include <windows.h>
2122

22-
namespace vcc { namespace core { namespace utils
23+
namespace vcc::core::utils
2324
{
24-
2525
LIBCOMMON_EXPORT std::string load_string(HINSTANCE instance, UINT id)
2626
{
27-
LPWSTR buffer_ptr = nullptr;
28-
const auto buffer_length(LoadStringW(instance, id, reinterpret_cast<LPWSTR>(&buffer_ptr), 0));
29-
if (buffer_length < 1 || buffer_ptr == nullptr)
30-
{
31-
return { };
32-
}
27+
// Get len of string to load
28+
const int length = LoadStringW(instance, id, nullptr, 0);
29+
if (length == 0)
30+
return {};
31+
32+
// Copy load string to wide_str
33+
std::wstring wide_str(length, L'\0');
34+
const int copied = LoadStringW(instance, id, wide_str.data(), length + 1);
35+
if (copied == 0)
36+
return {};
37+
38+
// Get len of string when converted
39+
const int utf8_len = WideCharToMultiByte(CP_UTF8, 0, wide_str.data(), copied, nullptr, 0, nullptr, nullptr);
40+
if (utf8_len == 0)
41+
return {};
42+
43+
// Convert string from wide_str to utf8_str
44+
std::string utf8_str(utf8_len, '\0');
45+
WideCharToMultiByte(CP_UTF8, 0, wide_str.data(), copied, utf8_str.data(), utf8_len, nullptr, nullptr);
3346

34-
return std::wstring_convert<std::codecvt_utf8<wchar_t>>().to_bytes(buffer_ptr, buffer_ptr + buffer_length);
47+
return utf8_str;
3548
}
49+
}
3650

37-
} } }

vcc-base.props

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
</PropertyGroup>
1010
<ItemDefinitionGroup>
1111
<ClCompile>
12+
<LanguageStandard>stdcpp17</LanguageStandard>
1213
<WarningLevel>Level3</WarningLevel>
1314
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
1415
<BrowseInformation>true</BrowseInformation>
@@ -20,4 +21,5 @@
2021
</Link>
2122
</ItemDefinitionGroup>
2223
<ItemGroup />
23-
</Project>
24+
</Project>
25+

0 commit comments

Comments
 (0)