//将char 转换 LPTSTR
 void StrClass::CharToLPTSTR(char sText[]){
   
  DWORD dwNum = MultiByteToWideChar (CP_ACP, 0, sText, -1, NULL, 0);
  wchar_t *pwText;
  pwText = new wchar_t[dwNum];
  if(!pwText)
  {
   delete []pwText;
  }  
   MultiByteToWideChar (CP_ACP, 0, sText, -1, pwText, dwNum);
   delete []pwText;   return ?? //我要把pwText中的内容返回出来。   /*
   这里如果这样可以返回
}

解决方案 »

  1.   

    //将char   转换   LPTSTR 
      void   StrClass::CharToLPTSTR(char   sText[]){ 
          
        DWORD   dwNum   =   MultiByteToWideChar   (CP_ACP,   0,   sText,   -1,   NULL,   0); 
        wchar_t   *pwText; 
        pwText   =   new   wchar_t[dwNum]; 
        if(!pwText) 
        { 
          delete   []pwText; 
        }     
          MultiByteToWideChar   (CP_ACP,   0,   sText,   -1,   pwText,   dwNum); 
           /* 
          这里如果这样可以返回 
           LPTSTR tempv=pwText;
          return tempv; //可以返回值但不能调用2次。第一次调用的值会被第二次覆盖
           */      delete   []pwText;       return   ??   //我要把pwText中的内容返回出来。      }放狗搜了一圈也没有找到答案!恳请高手指点!
      

  2.   

    pwText = new wchar_t[dwNum]; 
    CharToLPTSTR(char sText[],wchar_t  *pwText);
    ----------------
    改一下,pwText在外面建好,传进去。这样可以把值带出来。
      
      

  3.   

    顺便问个问题:VC是大小写敏感的么 ?
    我上次写了个程序,MessageBox函数好像一定要M和B大写,否则编译器会提示未定义的符号。
    可是主函数WinMain中的参数 hinstance可以不用大写也可以的。不知道究竟怎么规定的!@
      

  4.   

    首你这个函数设计不怎么样。
    void       StrClass::CharToLPTSTR(char       sText[])
    一般传入数组的时候,都应该加上传入的长度。
    void       StrClass::CharToLPTSTR(char       sText[], long szText)
    然后是,你要将你要的转换送出来,大概3种方式:
    1、将它作为返回值
    2、将它作为参数
    3、将它放在一个成员变量中(或者是全局变量,或者是静态变量)
    这就不依次讲了。另外,你应该在delete这个内存之前,把结果返回去。要不然,返回的是垃圾数据。