forked from AlloyTeam/webtop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CodeConvertor.cpp
36 lines (29 loc) · 891 Bytes
/
CodeConvertor.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
26
27
28
29
30
31
32
33
34
35
36
#include "CodeConvertor.h"
CodeConvertor::CodeConvertor(void)
{
}
CodeConvertor::~CodeConvertor(void)
{
}
LPCSTR CodeConvertor::Gb2Utf8(LPCSTR input)
{
WCHAR *temp;
int i = MultiByteToWideChar(CP_ACP, 0, input, -1, NULL, 0);
temp = new WCHAR[i+1];
MultiByteToWideChar(CP_ACP, 0, input, -1, temp, i);
i = WideCharToMultiByte(CP_UTF8, 0, temp, -1, NULL, 0, NULL, NULL);
CHAR* output = new CHAR[i+1];
int j=WideCharToMultiByte(CP_UTF8, 0, temp, -1, output, i, NULL, NULL);
return output;
}
LPCSTR CodeConvertor::Utf82Gb(LPCSTR input)
{
WCHAR *temp;
int i = MultiByteToWideChar(CP_UTF8, 0, input, -1, NULL, 0);
temp = new WCHAR[i+1];
MultiByteToWideChar(CP_UTF8, 0, input, -1, temp, i);
i = WideCharToMultiByte(CP_ACP, 0, temp, -1, NULL, 0, NULL, NULL);
CHAR* output = new CHAR[i+1];
int j=WideCharToMultiByte(CP_ACP, 0, temp, -1, output, i, NULL, NULL);
return output;
}