-
Notifications
You must be signed in to change notification settings - Fork 0
/
pch.cpp
25 lines (21 loc) · 870 Bytes
/
pch.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// pch.cpp: source file corresponding to the pre-compiled header
#include "pch.h"
// When you are using pre-compiled headers, this source file is necessary for compilation to succeed.
int WideCharToUtf8(LPSTR lpszUtf8, int nBuffLen, LPCWSTR lpszWideChar)
{
int wlen = wcslen(lpszWideChar);
int nLen = WideCharToMultiByte(CP_UTF8, 0, lpszWideChar, wlen, NULL, 0, NULL, NULL);
if (nBuffLen <= nLen)
nLen = nBuffLen - 1;
lpszUtf8[nLen] = '\0';
return WideCharToMultiByte(CP_UTF8, 0, lpszWideChar, wlen, lpszUtf8, nLen, NULL, NULL);
}
int Utf8ToWideChar(LPWSTR lpszWideStr, int nBuffLen, LPCSTR lpszUtf8)
{
int utf8_len = strlen(lpszUtf8);
int nLen = MultiByteToWideChar(CP_UTF8, 0, lpszUtf8, utf8_len, NULL, NULL);
if (nBuffLen <= nLen)
return -1;
lpszWideStr[nLen] = '\0';
return MultiByteToWideChar(CP_UTF8, 0, lpszUtf8, utf8_len, lpszWideStr, nLen);
}