Error argument of type "char *" is incompatible with parameter of type "LPCWSTR"

Source: Internet
Author: User

 

 

Method 1:

Method 1: For Beginners, modify the encoding format in vs2010:

Right-click the project --"

Select "Properties" --"

Select "Configuration Properties" --"

Select "General" --"

Finally, change "Character Set" under "Project Default" to "Use Multi-Byte Character Set" ("Use Unicode Character Set" by Default ")

 

This saves a lot of time for converting the type display. But this is not good for learning windows, because it cannot understand the features of windows Programming and the principles of character formats. If you have the energy, please do not use method 1. If you have more efforts, please refer to methods 2 and 3. You will learn a lot. This is the case for learning programming. Do not covet yourself and be sure to avoid suffering. If you encounter any difficulties, try your best to understand:

1. Why is this error?

2. How can this error be solved?

3. which method is the best? Why?

4. Lenovo has encountered similar problems, such as comparison, consideration, and summary.

I believe you will go further.

 

Method 2:

Method 2: # include <tchar. h> must be introduced before TEXT can be used for conversion.

  1. LPCWSTR str1 = TEXT ("Hello ");
  2. LPCWSTR str2 = L "Hello ";
  3. LPCWSTR str3 = _ T ("Hello ");

 

Method 3:

This is a solution for storing strings using variables.

    1. Const char * ch = "Hello ";
    2. WCHAR wCh [6];
    3. MultiByteToWideChar (, ch, 5, wCh, 6); // for usage of the MultiByteToWideChar function, see MSDN
    4. LPCWSTR str4 = wCh;

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.