xiaoxiaoling

C++博客 首页 新随笔 联系 聚合 管理
  17 Posts :: 2 Stories :: 9 Comments :: 0 Trackbacks

TCHAR tcScriptName[MAX_PATH];
tcScriptName = "filename";
size_t i;
  char tmp[MAX_PATH];
  mbstate_t       mbstate;

  // Reset to initial shift state
  ::memset((void*)&mbstate, 0, sizeof(mbstate));

  const wchar_t* wt = tcScriptName;
  wcsrtombs_s(&i, tmp, MAX_PATH, &wt, MAX_PATH,&mbstate);


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


char * input = null;
wchar_t wc_input[MAX_USERNAME_LEN] = L"test";

  int nLen = WideCharToMultiByte( CP_ACP, 0, wc_input, -1, NULL, 0, NULL, NULL );
  int i = wcslen(wc_input)*sizeof(wchar_t);
  input = (char*)realloc(input,i+1);
  if (!input)
  {
   free(input);
   input = (char*)malloc(i + 1);
  }
  WideCharToMultiByte( CP_ACP, 0, wc_input, -1, input, nLen, NULL, NULL );


 

posted on 2008-10-14 14:26 clcl 阅读(7982) 评论(4)  编辑 收藏 引用

Feedback

# re: Tchar转char 2009-02-23 16:59 miwa
多谢多谢  回复  更多评论
  

# re: Tchar转char 2009-03-11 16:37 陈凌
@miwa
不用  回复  更多评论
  

# re: Tchar转char 2011-02-15 16:59 小尧
先收藏了。谢谢PZ了。  回复  更多评论
  

# re: Tchar转char 2011-09-26 05:50
收藏了!  回复  更多评论
  


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理