char * CTools::CStringToCharP( CString strIn )
{
char * buffer = NULL;
int iTextLen;
iTextLen = WideCharToMultiByte( CP_ACP,0,strIn,-1,NULL,0,NULL,NULL );
buffer = NULL;
buffer = new char[iTextLen + 1];
memset( ( void* )buffer, 0, sizeof( char ) * ( iTextLen + 1 ) );
::WideCharToMultiByte( CP_ACP,0,strIn,-1,buffer,iTextLen,NULL,NULL );
return buffer;
}
{
char * buffer = NULL;
int iTextLen;
iTextLen = WideCharToMultiByte( CP_ACP,0,strIn,-1,NULL,0,NULL,NULL );
buffer = NULL;
buffer = new char[iTextLen + 1];
memset( ( void* )buffer, 0, sizeof( char ) * ( iTextLen + 1 ) );
::WideCharToMultiByte( CP_ACP,0,strIn,-1,buffer,iTextLen,NULL,NULL );
return buffer;
}
本文介绍了一种将MFC中的CString对象转换为C风格字符串的方法。通过使用WideCharToMultiByte函数,实现了从宽字符到多字节字符的转换,并确保了内存的正确初始化。
2225

被折叠的 条评论
为什么被折叠?



