add support for codepage selection in winchar_*ansi

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@4886 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
kichik 2007-01-25 13:04:52 +00:00
parent ac156f5ebe
commit 478f9536e4
2 changed files with 9 additions and 8 deletions

View file

@ -6,28 +6,29 @@
using std::runtime_error;
WCHAR *winchar_fromansi(const char* s) {
int l = MultiByteToWideChar(CP_ACP, 0, s, -1, 0, 0);
WCHAR *winchar_fromansi(const char* s, unsigned int codepage/*=CP_ACP*/)
{
int l = MultiByteToWideChar(codepage, 0, s, -1, 0, 0);
if (l == 0)
throw runtime_error("Unicode conversion failed");
WCHAR *ws = new WCHAR[l + 1];
if (MultiByteToWideChar(CP_ACP, 0, s, -1, ws, l + 1) == 0)
if (MultiByteToWideChar(codepage, 0, s, -1, ws, l + 1) == 0)
throw runtime_error("Unicode conversion failed");
return ws;
}
char *winchar_toansi(const WCHAR* ws)
char *winchar_toansi(const WCHAR* ws, unsigned int codepage/*=CP_ACP*/)
{
int l = WideCharToMultiByte(CP_ACP, 0, ws, -1, 0, 0, 0, 0);
int l = WideCharToMultiByte(codepage, 0, ws, -1, 0, 0, 0, 0);
if (l == 0)
throw runtime_error("Unicode conversion failed");
char *s = new char[l + 1];
if (WideCharToMultiByte(CP_ACP, 0, ws, -1, s, l + 1, 0, 0) == 0)
if (WideCharToMultiByte(codepage, 0, ws, -1, s, l + 1, 0, 0) == 0)
throw runtime_error("Unicode conversion failed");
return s;