• 不能将参数 2 从“const char *”转换为“LPCWSTR”【转】http://blog.sina.com.cn/s/blog_4a94a0db0100ktxp.html


    : 不能将参数 2 从“const char *”转换为“LPCWSTR”

    在VS2008下使用MFC编程遇到错误:
           error C2664: “CFrameWnd::Create”: 不能将参数 2 从“const char [12]”转换为“LPCTSTR”。
           解决办法:项目-属性-配置属性-常规,将字符集由“使用Unicode字符集”改为“使用多字字符集”。
           具体原因参照如下长篇大论:
    Problem This error message means that you are trying to pass a multi-byte string (const char [12]) to a function which expects a unicode string (LPCTSTR). The LPCTSTR type extends to const TCHAR*, where TCHAR is char when you compile for multi-byte and wchar_t for unicode. Since the compiler doesn't accept the char array, we can safely assume that the actual type of TCHAR, in this compilation, is wchar_t. Resolution You will have to do one of two things: Change your project configuration to use multibyte strings. Press ALT+F7 to open the properties, and navigate to Configuration Properties > General. Switch Character Set to "Use Multi-Byte Character Set". Indicate that the string literal, in this case "Hello world!" is of a specific encoding. This can be done through either prefixing it with L, such as L"Hello world!", or surrounding it with the generic _T("Hello world!") macro. The latter will expand to the L prefix if you are compiling for unicode (see #1), and nothing (indicating multi-byte) otherwise. Variations Another error message, indicating the same problem, would be: cannot convert parameter 1 from 'const char [12]' to 'LPCWSTR' Where LPCWSTR maps to a wchar_t pointer, regardless of your build configuration. This problem can be resolved primarily by using solution #2, but in some cases also #1. A lot of the Microsoft provided libraries, such as the Platform SDK, have got two variations of each function which takes strings as parameters. In case of a unicode build, the actual functions are postfixed W, such as the MessageBoxW seen above. In case of multi-byte, the function would be MessageBoxA (ASCII). Which of these functions is actually used when you compile your application, depends on the setting described in resolution #1 above.

  • 相关阅读:
    Scilab 的画图函数(2)
    Webapp的display-name问题
    记录:在老XPS1330上安装CentOS7
    包含Blob字段的表无法Export/Import
    记一段脚本的诞生
    一个短小的JS函数,用来得到仅仅包含不重复元素的数组
    然并卵
    Linux下的定时任务Crontab
    两段用来启动/重启Linux下Tomcat的Perl脚本
    JavaScript中给二维数组动态添加元素的质朴方法
  • 原文地址:https://www.cnblogs.com/songtzu/p/2859989.html
Copyright © 2020-2023  润新知