在VS2008中,用到FILE类型的文件读写fwrite,fread等操作时,利用MessageBox或者其他有关wchar_t、LPCSTCTR类型时,直接用char*出现了参数转换问题,查了下MSDN
范例:
#include <stdlib.h>
#include <stdio.h>
void main( void )
{
int i;
char *pmbnull = NULL;
char *pmbhello = (char *)malloc( MB_CUR_MAX );
wchar_t *pwchello = L"Hi";
wchar_t *pwc = (wchar_t *)malloc( sizeof( wchar_t ));
printf( "Convert to multibyte string:/n" );
i = wcstombs( pmbhello, pwchello, MB_CUR_MAX );
printf( "/tCharacters converted: %u/n", i );
printf( "/tHex value of first" );
printf( " multibyte character: %#.4x/n/n", pmbhello );
printf( "Convert back to wide-character string:/n" );
i = mbstowcs( pwc, pmbhello, MB_CUR_MAX );
printf( "/tCharacters converted: %u/n", i );
printf( "/tHex value of first" );
printf( " wide character: %#.4x/n/n", pwc );
}
Output
Convert to multibyte string:
Characters converted: 1
Hex value of first multibyte character: 0x0e1a
Convert back to wide-character string:
Characters converted: 1
Hex value of first wide character: 0x0e1e
char* wchar_t*得到了很好的处理。