这是GDI+中的Image函数的命名 Image myImage2(L"D:\\2.jpg");这样是成功的。但是我想用一个变量来表示"D:\\2.jpg",比如CString 的 Pic,就会提示无法从CString 转化为const WCHAR *,我试了几种方式转换都没有成功,有人了解怎么转换吗?

解决方案 »

  1.   

    这说明你的工程是ansi的
    需要先将CString的值转成unicode的才行
    用这个MultiByteToWideChar这个函数。具体使用查一下msdn
    定义一个WCHAR的数组,转换过来后再传进去就ok了
      

  2.   

    LPCTSTR lpszJPGName;或者TCHAR name[50];
    CString str;
    wcscpy(name,str);
      

  3.   

    #include <atlbase.h>USES_CONVERSION;
    WCHAR* pBuf = T2W((LPCTSTR)..);
      

  4.   

    CString strName="D:\\2.jpg";
    Image myImage2(strName.Getbuffer(0));
      

  5.   

    #include <atlbase.h>CString strText(_T("Hello,World!"));
    USES_CONVERSION; WCHAR* pBuf = T2W(strText.GetBuffer(strText.GetLength()));
    AfxMessageBox(pBuf);
    strText.ReleaseBuffer(strText.GetLength());
      

  6.   

    CString   str   =   "aklsdjf "; 
    TCHAR*   tch   =   (LPTSTR)(LPCTSTR)str;
      

  7.   

    MultiByteToWideChar 是多字节到UNICODE,就可以把char类型变成wchar类型了
    当然也有反过来的函数WideCharToMultiByte