代码
CFileDialog openDlg(true);
m_Bitmap_org = Bitmap::FromFile(openDlg.GetPathName());
用来动态打开文件,为啥会出现
error C2664: 'FromFile' : cannot convert parameter 1 from 'class CString' to 'const unsigned short *
这样的问题

解决方案 »

  1.   

    itmap::FromFile MethodThe FromFile method creates a Bitmap object based on an image file.Syntax    static Bitmap *FromFile(      
            const WCHAR *filename,
            BOOL useEmbeddedColorManagement
        );Parameters    filename
            [in] Pointer to a null-terminated string that specifies the path name of the image file. 
        useEmbeddedColorManagement
            [in] Optional. Boolean value that specifies whether the new Bitmap object applies color correction according to color management information that is embedded in the image file. Embedded information can include International Color Consortium (ICC) profiles, gamma values, and chromaticity information. TRUE specifies that color correction is enabled, and FALSE specifies that color correction is not enabled. The default value is FALSE. Return Value    This method returns a pointer to the new Bitmap object.
      

  2.   

    CString-->char*
    用GetBuffer(...);m_Bitmap_org = Bitmap::FromFile(openDlg.GetPathName().GetBuffer(0) ); 
      

  3.   

    用GetBuffer:
    error C2664: 'FromFile' : cannot convert parameter 1 from 'char *' to 'const unsigned short *'
            Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    Error executing cl.exe.…………
      

  4.   

    把工程的字符编码类型设为UNICODE就可以了;或者自己进行编码转换。
      

  5.   

    怎么这么多人错用GetBuffer,到底谁开始误导大家的啊?GetBuffer只是用于把一个字符串内部的可写缓冲区锁定并返回,在绝大多数情况都不需要用它他这个问题在于FromFile锁定必须用WCHAR,而他的编译环境是MBCS,合理的办法是用T2W宏转换一下