You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
100 lines
2.3 KiB
C
100 lines
2.3 KiB
C
|
12 years ago
|
#ifndef _TCONVERT
|
||
|
|
#define _TCONVERT
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#ifdef _TCONVERT
|
||
|
|
//=============================================================================
|
||
|
|
// class _tochar
|
||
|
|
// This class converts either WCHAR or CHAR string to a new CHAR string.
|
||
|
|
// Memory is allocated/deallocated using new/delete
|
||
|
|
//=============================================================================
|
||
|
|
class _tochar {
|
||
|
|
private:
|
||
|
|
BOOL m_bAutoDelete;
|
||
|
|
LPSTR m_szBuffer;
|
||
|
|
|
||
|
|
public:
|
||
|
|
_tochar(LPCWSTR wszText, BOOL bAutoDelete = TRUE)
|
||
|
|
{
|
||
|
|
m_bAutoDelete = bAutoDelete;
|
||
|
|
_ASSERTE(wszText);
|
||
|
|
int nLen = wcslen(wszText)+1;
|
||
|
|
m_szBuffer = new CHAR [nLen];
|
||
|
|
wcstombs(m_szBuffer, wszText, nLen);
|
||
|
|
}
|
||
|
|
_tochar(LPCSTR szText, BOOL bAutoDelete = TRUE)
|
||
|
|
{
|
||
|
|
m_bAutoDelete = bAutoDelete;
|
||
|
|
_ASSERTE(szText);
|
||
|
|
int nLen = strlen(szText) + 1;
|
||
|
|
m_szBuffer = new CHAR [nLen];
|
||
|
|
strcpy(m_szBuffer, szText);
|
||
|
|
}
|
||
|
|
~_tochar()
|
||
|
|
{
|
||
|
|
if (m_bAutoDelete) {
|
||
|
|
_ASSERTE(m_szBuffer);
|
||
|
|
delete [] m_szBuffer;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
operator LPSTR()
|
||
|
|
{
|
||
|
|
_ASSERTE(m_szBuffer);
|
||
|
|
return (LPSTR)m_szBuffer;
|
||
|
|
}
|
||
|
|
operator LPCSTR()
|
||
|
|
{
|
||
|
|
_ASSERTE(m_szBuffer);
|
||
|
|
return (LPCSTR)m_szBuffer;
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
//=============================================================================
|
||
|
|
// class _towchar
|
||
|
|
// This class converts either WCHAR or CHAR string to a new WCHAR string.
|
||
|
|
// Memory is allocated/deallocated using new/delete
|
||
|
|
//=============================================================================
|
||
|
|
|
||
|
|
class _towchar {
|
||
|
|
private:
|
||
|
|
BOOL m_bAutoDelete;
|
||
|
|
LPWSTR m_wszBuffer;
|
||
|
|
|
||
|
|
public:
|
||
|
|
_towchar(LPCWSTR wszText, BOOL bAutoDelete = TRUE)
|
||
|
|
{
|
||
|
|
m_bAutoDelete = bAutoDelete;
|
||
|
|
_ASSERTE(wszText);
|
||
|
|
int nLen = wcslen(wszText)+1;
|
||
|
|
m_wszBuffer = new WCHAR [nLen];
|
||
|
|
wcscpy(m_wszBuffer, wszText);
|
||
|
|
}
|
||
|
|
_towchar(LPCSTR szText, BOOL bAutoDelete = TRUE)
|
||
|
|
{
|
||
|
|
m_bAutoDelete = bAutoDelete;
|
||
|
|
_ASSERTE(szText);
|
||
|
|
int nLen = strlen(szText) + 1;
|
||
|
|
m_wszBuffer = new WCHAR [nLen];
|
||
|
|
mbstowcs(m_wszBuffer, szText, nLen);
|
||
|
|
}
|
||
|
|
~_towchar()
|
||
|
|
{
|
||
|
|
if (m_bAutoDelete) {
|
||
|
|
_ASSERTE(m_wszBuffer);
|
||
|
|
delete [] m_wszBuffer;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
operator LPWSTR()
|
||
|
|
{
|
||
|
|
_ASSERTE(m_wszBuffer);
|
||
|
|
return (LPWSTR)m_wszBuffer;
|
||
|
|
}
|
||
|
|
operator LPCWSTR()
|
||
|
|
{
|
||
|
|
_ASSERTE(m_wszBuffer);
|
||
|
|
return (LPCWSTR)m_wszBuffer;
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
#endif
|