Creates a UTF-16 wide string from the given ANSI string, allocating memory using new. The caller is responsible for deleting the return value using delete[]. Returns the wide string, or NULL if the input is NULL.
| 2322 | // value using delete[]. Returns the wide string, or NULL if the |
| 2323 | // input is NULL. |
| 2324 | LPCWSTR String::AnsiToUtf16(const char* ansi) { |
| 2325 | if (!ansi) return NULL; |
| 2326 | const int length = strlen(ansi); |
| 2327 | const int unicode_length = |
| 2328 | MultiByteToWideChar(CP_ACP, 0, ansi, length, |
| 2329 | NULL, 0); |
| 2330 | WCHAR* unicode = new WCHAR[unicode_length + 1]; |
| 2331 | MultiByteToWideChar(CP_ACP, 0, ansi, length, |
| 2332 | unicode, unicode_length); |
| 2333 | unicode[unicode_length] = 0; |
| 2334 | return unicode; |
| 2335 | } |
| 2336 | |
| 2337 | // Creates an ANSI string from the given wide string, allocating |
| 2338 | // memory using new. The caller is responsible for deleting the return |
nothing calls this directly
no outgoing calls
no test coverage detected