more simple TCHARs fixes

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6047 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
wizou 2010-04-12 16:00:17 +00:00
parent a92fad7347
commit 64a0f32e52
38 changed files with 1831 additions and 1961 deletions

View file

@ -19,6 +19,7 @@
#ifndef _TSTRING_
#define _TSTRING_
#include "Platform.h"
#include "tchar.h"
#include <string>
@ -28,9 +29,7 @@ typedef std::wstring tstring;
typedef std::wofstream tofstream;
typedef std::wifstream tifstream;
// Use the following macros to open text files.
// #define FOPENTEXT(file, mode) _wfopen(file, mode ## L", ccs=Unicode")
FILE* FileOpenUnicodeText(const TCHAR* file, const TCHAR* mode);
#define FOPENTEXT(file, mode) FileOpenUnicodeText(file, mode)
#define FOPENTEXT(file, mode) _wfopen(file, mode)
#else
typedef std::string tstring;
typedef std::ofstream tofstream;
@ -56,10 +55,16 @@ public:
m_wStr = (wchar_t*) GlobalAlloc(GPTR, len*sizeof(wchar_t));
MultiByteToWideChar(CP_ACP, 0, str, -1, m_wStr, len);
}
CtoTString(const std::string& str)
{
int len = MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.length()+1, NULL, 0);
m_wStr = (wchar_t*) GlobalAlloc(GPTR, len*sizeof(wchar_t));
MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.length()+1, m_wStr, len);
}
~CtoTString() { GlobalFree(m_wStr); m_wStr = 0; }
operator const wchar_t* tstr() { return m_wStr; }
operator const wchar_t*() { return m_wStr; }
private:
wchar_t* m_wStr;
@ -76,6 +81,12 @@ public:
m_cStr = (char*) GlobalAlloc(GPTR, len);
WideCharToMultiByte(CP_ACP, 0, wStr, -1, m_cStr, len, 0, 0);
}
TtoCString(const tstring& wStr)
{
int len = WideCharToMultiByte(CP_ACP, 0, wStr.c_str(), wStr.length()+1, NULL, 0, 0, 0);
m_cStr = (char*) GlobalAlloc(GPTR, len);
WideCharToMultiByte(CP_ACP, 0, wStr.c_str(), wStr.length()+1, m_cStr, len, 0, 0);
}
~TtoCString() { GlobalFree(m_cStr); m_cStr = 0; }