首页 > 代码库 > char* to LPTSTR

char* to LPTSTR

1,char* to LPTSTR

LPTSTR Char2LPTSTR(char* mchar)
{
  int length ;
  wchar_t* pWChar;
  length = MultiByteToWideChar (CP_OEMCP, 0, mchar, -1, NULL, 0) ;
  if(length<=0)return NULL;
  pWChar=new wchar_t[length+1];
  memset(pWChar,0,length+1);
  MultiByteToWideChar (CP_OEMCP, 0, mchar, -1, pWChar, length+1) ;
  return pWChar;
}

注意用完后要及时

delete [] pWChar;

2, CString to char* 

char* pmodel=(LPSTR)(LPCTSTR)csSelectedModel;