This repository was archived by the owner on Dec 15, 2022. It is now read-only.
File tree 1 file changed +36
-1
lines changed
1 file changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -69,6 +69,41 @@ std::string wideCharToAnsi(LPWSTR wide_char) {
69
69
return result;
70
70
}
71
71
72
+ std::string wideCharToUtf8 (LPWSTR wide_char) {
73
+ if (wide_char == NULL ) {
74
+ return std::string ();
75
+ }
76
+
77
+ int utf8_length = WideCharToMultiByte (CP_UTF8,
78
+ 0 ,
79
+ wide_char,
80
+ -1 ,
81
+ NULL ,
82
+ 0 ,
83
+ NULL ,
84
+ NULL );
85
+ if (utf8_length == 0 ) {
86
+ return std::string ();
87
+ }
88
+
89
+ char * buffer = new char [utf8_length];
90
+ if (WideCharToMultiByte (CP_ACP,
91
+ 0 ,
92
+ wide_char,
93
+ -1 ,
94
+ buffer,
95
+ utf8_length,
96
+ NULL ,
97
+ NULL ) == 0 ) {
98
+ delete[] buffer;
99
+ return std::string ();
100
+ }
101
+
102
+ std::string result = std::string (buffer);
103
+ delete[] buffer;
104
+ return result;
105
+ }
106
+
72
107
std::string getErrorMessage (DWORD errorCode) {
73
108
LPWSTR errBuffer;
74
109
::FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
@@ -215,7 +250,7 @@ KEYTAR_OP_RESULT FindCredentials(const std::string& service,
215
250
continue ;
216
251
}
217
252
218
- std::string login = wideCharToAnsi (cred->UserName );
253
+ std::string login = wideCharToUtf8 (cred->UserName );
219
254
std::string password (
220
255
reinterpret_cast <char *>(
221
256
cred->CredentialBlob ),
You can’t perform that action at this time.
0 commit comments