Win32 Application Programming C++, Error with parameter Type LPCWSTR

前端 未结 4 1211
心在旅途
心在旅途 2020-12-07 05:06

I am constructing a program using the Win32 Application on Visual Studio 2013. From the tutorials I have read, I know this following code is correct, but I don\'t know where

4条回答
  •  时光说笑
    2020-12-07 06:05

    First and foremost, you need to decide what type of project you are trying to create with regard to character set. You have at least four options for project type

    1. Project that uses regular (narrow) characters only (char)
    2. Project that uses wide characters only (wchar_t)
    3. "Transformer" project that can be easily compiled as either type 1 or type 2 by a simple change in project settings
    4. Project that freely mixes narrow and wide characters

    This is the decision that you have to make first. There's no point in proceeding before you make that decision.

    Now, depending on the choice you made, you should proceed as follows

    1. Regular char project

      • Go to project settings and set "Character Set" to "Use Multi-Byte Character Set"
      • In your code use regular (narrow) string and character literals: "Edit", 'A' etc.
      • Use regular char, char [N], char * and std::string types to work with characters and strings
      • Use narrow versions of standard library functions: printf, strcpy etc.
      • Use either "normal" names to call Windows API functions: CreateWindowEx, or their narrow names: CreateWindowExA (whichever you like better)
    2. Wide wchar_t project

      • Go to project settings and set "Character Set" to "Use Unicode Character Set"
      • In your code explicitly use wide string and character literals: L"Edit", L'A' etc.
      • Use wide wchar_t, wchar_t [N], wchar_t * and std::wstring types to work with characters and strings
      • Use wide versions of standard library functions: wprintf, wcscpy etc.
      • Use either "normal" names to call Windows API functions: CreateWindowEx, or their wide names: CreateWindowExW (whichever you like better)
    3. "Transformer" project

      • Include into every translation unit
      • In your code always explicitly use macro _T with string and character literals: _T("Edit"), _T('A') etc.
      • Use TCHAR, TCHAR [N], TCHAR * and std::basic_string types to work with characters and strings
      • Use "transformer" versions of standard library functions: _tprintf, _tcscpy etc.
      • Use "normal" names to call Windows API functions: CreateWindowEx  
         
        With this kind of project, if you do everything properly, you will be able to automatically switch between type 1 and type 2 by simply changing the "Character Set" setting in project settings.
    4. Mix-and-match project

      • Use whatever type of character you prefer (narrow or wide) in each specific context, but remember to call the proper version of standard library and Windows API function for each character type. In some cases, when narrow and wide contexts meet, you will have to perform conversions between narrow and wide character types.

    Of course, if you started a project of type 1 or type 2, you can always turn it into a project of type 4 by starting to mix character types. But if you need a type 3 project, it is a good idea to stick to its principles from the very beginning (converting to type 3 later is a very laborious process).


    It is not immediately obvious what you are trying to do in your project. But a wild guess would be that you are trying to build a type 1 project. In that case all you need to do to fix the problem is go to project settings and set "Character Set" to "Use Multi-Byte Character Set".

提交回复
热议问题