Skip to content

Commit

Permalink
Target down to Win2K
Browse files Browse the repository at this point in the history
  • Loading branch information
Tatsh committed Oct 22, 2023
1 parent a62c0f1 commit c0ff2e8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ add_executable(
shell.c
shell.h
msvc.h)
target_compile_definitions(winprefs PRIVATE UNICODE _UNICODE)
target_compile_definitions(winprefs PRIVATE UNICODE _UNICODE _WIN32_WINNT=0x0500)
target_link_libraries(winprefs PRIVATE shlwapi)
if(CMAKE_BUILD_TYPE MATCHES "Debug|RelWithDebInfo" AND WITH_VLD)
target_compile_definitions(winprefs PRIVATE ENABLE_VLD)
Expand Down
5 changes: 5 additions & 0 deletions native/msvc.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@
#define false FALSE
#endif

#ifndef WC_ERR_INVALID_CHARS
#define WC_ERR_INVALID_CHARS 0
#define _WC_ERR_INVALID_CHARS 0x0080
#endif

#endif // MSVC_H
25 changes: 21 additions & 4 deletions native/reg_command.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#include <stdio.h>
#include <wchar.h>

#include <windows.h>
// Has to come after
#include <versionhelpers.h>

#include "constants.h"
#include "reg_command.h"
#include "shell.h"
Expand Down Expand Up @@ -140,11 +144,24 @@ void do_write_reg_command(FILE *out_fp,
if (((size_t)wrote < CMD_MAX_COMMAND_LENGTH) ||
((size_t)wrote == CMD_MAX_COMMAND_LENGTH && out[CMD_MAX_COMMAND_LENGTH - 1] == L'f' &&
out[CMD_MAX_COMMAND_LENGTH - 2] == L'/' && out[CMD_MAX_COMMAND_LENGTH - 3] == L' ')) {
size_t req_size = (size_t)WideCharToMultiByte(
CP_UTF8, WC_ERR_INVALID_CHARS, out, -1, NULL, 0, NULL, NULL);
size_t req_size =
(size_t)WideCharToMultiByte(CP_UTF8,
IsWindowsVistaOrGreater() ? _WC_ERR_INVALID_CHARS : 0,
out,
-1,
NULL,
0,
NULL,
NULL);
char *mb_out = malloc(req_size);
WideCharToMultiByte(
CP_UTF8, WC_ERR_INVALID_CHARS, out, -1, mb_out, (int)req_size, NULL, NULL);
WideCharToMultiByte(CP_UTF8,
IsWindowsVistaOrGreater() ? _WC_ERR_INVALID_CHARS : 0,
out,
-1,
mb_out,
(int)req_size,
NULL,
NULL);
fprintf(out_fp, "%s\n", mb_out);
free(mb_out);
} else {
Expand Down

0 comments on commit c0ff2e8

Please sign in to comment.