CString CharToCString(char *pText)
{
int iLength = 0;
wchar_t *pwText = NULL;
CString csText = _T("");
/* Get the number of wide character array */
iLength = MultiByteToWideChar(CP_ACP, 0x00, pText, -1, NULL, 0);
if ( iLength > 0 )
{
/* Allocate wide character array */
pwText = new wchar_t[iLength];
if ( pwText != NULL )
{
/* Convert to ASCII */
MultiByteToWideChar(CP_ACP, 0x00, pText, -1, pwText, iLength);
/* Convert to CString */
csText = pwText;
/* Release memory */
delete []pwText;
pwText = NULL;
}
}
return csText;
}
char* CStringToChar(CString csBuffer)
{
int iLen = 0;
char *pBuf = NULL;
/** Convert wide char into char */
iLen = WideCharToMultiByte(CP_ACP, NULL, csBuffer, -1, NULL, 0, NULL, FALSE);
/** Create char pointer space */
pBuf = new char[iLen];
if ( pBuf != NULL )
{
WideCharToMultiByte(CP_ACP, NULL, csBuffer, -1, pBuf, iLen, NULL, FALSE);
}
return pBuf;
}
{
int iLength = 0;
wchar_t *pwText = NULL;
CString csText = _T("");
/* Get the number of wide character array */
iLength = MultiByteToWideChar(CP_ACP, 0x00, pText, -1, NULL, 0);
if ( iLength > 0 )
{
/* Allocate wide character array */
pwText = new wchar_t[iLength];
if ( pwText != NULL )
{
/* Convert to ASCII */
MultiByteToWideChar(CP_ACP, 0x00, pText, -1, pwText, iLength);
/* Convert to CString */
csText = pwText;
/* Release memory */
delete []pwText;
pwText = NULL;
}
}
return csText;
}
char* CStringToChar(CString csBuffer)
{
int iLen = 0;
char *pBuf = NULL;
/** Convert wide char into char */
iLen = WideCharToMultiByte(CP_ACP, NULL, csBuffer, -1, NULL, 0, NULL, FALSE);
/** Create char pointer space */
pBuf = new char[iLen];
if ( pBuf != NULL )
{
WideCharToMultiByte(CP_ACP, NULL, csBuffer, -1, pBuf, iLen, NULL, FALSE);
}
return pBuf;
}