36
\brief Win32-specific API functions.
37
\note The public API works with UTF-8 strings, unless noted otherwise.
32
// Note: The public API works with UTF-8 strings, unless noted otherwise.
35
// Get a list of drives available for the user. The drives are in
36
// "C:\" format (uppercase, utf-8).
45
/// Get a list of drives available for the user. The drives are in
46
/// "C:\" format (uppercase, utf-8).
37
47
template<class Container> inline
38
48
bool win32_get_drive_list(Container& put_here);
41
// Get windows "special" folder by CSIDL (CSIDL_APPDATA, for example).
42
// See http://msdn.microsoft.com/en-us/library/bb762494(VS.85).aspx
51
/// Get windows "special" folder by CSIDL (CSIDL_APPDATA, for example).
52
/// See http://msdn.microsoft.com/en-us/library/bb762494(VS.85).aspx
44
54
inline std::string win32_get_special_folder(int csidl, bool auto_create = true);
47
// Usually C:\Windows or something like that.
57
/// Usually C:\\Windows or something like that.
48
58
inline std::string win32_get_windows_directory();
51
// base may be e.g. HKEY_CURRENT_USER.
52
// Note that this works only with REG_SZ (string) types,
53
// returning their value as utf-8. False is returned for all other types.
61
/// Get registry value as a string.
62
/// Base may be e.g. HKEY_CURRENT_USER.
63
/// Note that this works only with REG_SZ (string) types,
64
/// returning their value as utf-8. False is returned for all other types.
54
65
inline bool win32_get_registry_value_string(HKEY base,
55
66
const std::string& keydir, const std::string& key, std::string& put_here);
58
// Note that this sets the type as REG_SZ (string). The accepted utf-8
59
// value is converted to utf-16 for storage.
69
/// Set registry value as a string.
70
/// Note that this sets the type as REG_SZ (string). The accepted utf-8
71
/// value is converted to utf-16 for storage.
60
72
inline bool win32_set_registry_value_string(HKEY base,
61
73
const std::string& keydir, const std::string& key, const std::string& value);
64
// Redirect stdout and stderr to console window (if open).
65
inline bool win32_redirect_stdio_to_console();
68
// Redirect stdout to stdout.txt and stderr to stderr.txt.
76
/// Redirect stdout and stderr to console window (if open). Requires winxp (at compile-time).
77
/// \param create_if_none if true, create a new console if none was found and attach to it.
78
/// \return false if failed or unsupported.
79
inline bool win32_redirect_stdio_to_console(bool create_if_none = false);
82
/// Redirect stdout and stderr to console window (if open). Requires winxp (at compile-time).
83
/// \param create_if_none if true, create a new console if none was found and attach to it.
84
/// \param console_created Set to true if a new console was created due to \c create_if_none.
85
/// \return false if failed or unsupported.
86
inline bool win32_redirect_stdio_to_console(bool create_if_none, bool& console_created);
89
/// Redirect stdout to stdout.txt and stderr to stderr.txt.
91
/// \return true on success, false on failure.
70
92
inline bool win32_redirect_stdio_to_files(std::string stdout_file = "", std::string stderr_file = "");
73
// Convert a string in user-specified encoding to utf-16 string (00-terminated array of wchar_t).
74
// wchar_t is 2 bytes on windows, thus holding utf-16 code unit.
75
// Caller must delete[] the returned value.
76
// returned_buf_size (if not 0) will be set to the size of returned buffer
77
// (in wchar_t; including terminating 00). The byte size will be (returned_buf_size*2).
95
/// Convert a string in user-specified encoding to utf-16 string (00-terminated array of wchar_t).
96
/// wchar_t is 2 bytes on windows, thus holding utf-16 code unit.
97
/// Caller must delete[] the returned value.
98
/// returned_buf_size (if not 0) will be set to the size of returned buffer
99
/// (in wchar_t; including terminating 00). The byte size will be (returned_buf_size*2).
78
100
inline wchar_t* win32_user_to_utf16(UINT from_cp, const char* from_str, unsigned int* returned_buf_size = 0);
81
// Convert utf-16 string (represented as 0-terminated array of wchar_t, where
82
// wchar_t is 2 bytes (on windows)) to a string in user-specified encoding.
83
// Caller must delete[] the returned value.
84
// The size of the returned buffer is std::strlen(buf) + 1.
85
// returned_buf_size (if not 0) will be set to the size of returned buffer
86
// (in char; including terminating 0).
103
/// Convert utf-16 string (represented as 0-terminated array of wchar_t, where
104
/// wchar_t is 2 bytes (on windows)) to a string in user-specified encoding.
105
/// Caller must delete[] the returned value.
106
/// The size of the returned buffer is std::strlen(buf) + 1.
107
/// returned_buf_size (if not 0) will be set to the size of returned buffer
108
/// (in char; including terminating 0).
87
109
inline char* win32_utf16_to_user(UINT to_cp, const wchar_t* utf16_str, unsigned int* returned_buf_size = 0);
90
// Convert utf-8 string to utf-16 string. See win32_user_to_utf16() for details.
112
/// Convert utf-8 string to utf-16 string. See win32_user_to_utf16() for details.
91
113
inline wchar_t* win32_utf8_to_utf16(const char* utf8_str, unsigned int* returned_buf_size = 0);
94
// Convert utf-16 string to utf-8 string. See win32_utf16_to_user() for details.
116
/// Convert utf-16 string to utf-8 string. See win32_utf16_to_user() for details.
95
117
inline char* win32_utf16_to_utf8(const wchar_t* utf16_str, unsigned int* returned_buf_size = 0);
98
// Same as win32_utf16_to_utf8(), but safer since it never returns 0 (it returns "" instead).
99
// Note that we don't provide non-utf8 versions of this function, because the other charsets
100
// may actually be multi-byte (std::string can't hold their terminating 0 properly).
101
// Also, we don't provide std::wstring versions for utf16, because they are not always
102
// supported by non-MS compilers (mingw, for example).
120
/// Same as win32_utf16_to_utf8(), but safer since it never returns 0 (it returns "" instead).
121
/// Note that we don't provide non-utf8 versions of this function, because the other charsets
122
/// may actually be multi-byte (std::string can't hold their terminating 0 properly).
123
/// Also, we don't provide std::wstring versions for utf16, because they are not always
124
/// supported by non-MS compilers (mingw, for example).
103
125
inline std::string win32_utf16_to_utf8_string(const wchar_t* utf16_str);
106
// Convert current locale-encoded string to utf-16 string. See win32_user_to_utf16() for details.
107
// Use CP_ACP is system default windows ANSI codepage.
108
// Use CP_THREAD_ACP is for current thread. Think before you choose. :)
128
/// Convert current locale-encoded string to utf-16 string. See win32_user_to_utf16() for details.
129
/// Use CP_ACP is system default windows ANSI codepage.
130
/// Use CP_THREAD_ACP is for current thread. Think before you choose. :)
109
131
inline wchar_t* win32_locale_to_utf16(const char* loc_str, unsigned int* returned_buf_size = 0,
110
132
bool use_thread_locale = false);
113
// Convert utf-16 string to locale-encoded string. See win32_utf16_to_user() for details.
135
/// Convert utf-16 string to locale-encoded string. See win32_utf16_to_user() for details.
114
136
inline char* win32_utf16_to_locale(const wchar_t* utf16_str, unsigned int* returned_buf_size = 0,
115
137
bool use_thread_locale = false);
118
// Convert current locale-encoded string to utf-8 string. The returned value must be freed by caller.
140
/// Convert current locale-encoded string to utf-8 string. The returned value must be freed by caller.
119
141
inline char* win32_locale_to_utf8(const char* loc_str, unsigned int* returned_buf_size = 0,
120
142
bool use_thread_locale = false);
123
// Convert utf-8 string to locale-encoded string. See win32_utf8_to_user() for details.
124
inline char* win32_utf8_to_locale(const wchar_t* utf8_str, unsigned int* returned_buf_size = 0,
145
/// Convert utf-8 string to locale-encoded string. See win32_utf8_to_user() for details.
146
inline char* win32_utf8_to_locale(const char* utf8_str, unsigned int* returned_buf_size = 0,
125
147
bool use_thread_locale = false);