Error: none of the 2 overloads could convert all the argument types

Description of the error:

Some programs run well under VC6, but report errors under VC2008 and later versions of VC(The following only to VC2008 for example, high version VC similar), such as using the following statement:

outtextxy(10, 20, "Hello World");

It can be compiled successfully under VC6, but there will be an error after compiling under VC2008.

The error prompts are as follows:

error C2665: 'outtextxy' : none of the 2 overloads could convert all the argument types

Similarly, similar problems can be encountered with other functions that contain string calls, such as loadimage, drawtext, and so on.

Cause of error

Simply put, this is due to character encoding issues.

VC6 uses MBCS encoding by default, while VC2008 and high-version VC use Unicode encoding by default. The problem is explained in detail below:

When characters are represented by char, English takes up one byte and Chinese two bytes. There is a serious question: Two consecutive bytes, two English characters, or one Chinese characters? To solve this problem, Unicode coding was born. Unicode encoding is represented by two bytes in both Chinese and English.

For MBCS encoding, character variables are defined by char.

For Unicode encoding, character variables are defined by wchar_t .

To improve the adaptability of the code, Microsoft defines TCHAR in tchar.h, which automatically expands to char or wchar_t, based on the encoding defined by the project.

Most string pointers in Windows APIs and EasyX use LPCTSTR or LPTSTR types, and LPCTSTR/LPTSTR is an abbreviation for "Long Point (Const) Tchar STRing". Therefore, it can be argued that LPCTSTR is const TCHAR * and LPTSTR is TCHAR *.

Thus, in VS2008, the aforementioned error is prompted when the char string is passed to the function.

Solution:

Although there are several workarounds, the goal is the same: to match the character encoding.

Method 1: Modify all strings to the TCHAR version.

In brief, we need to pay attention to the following points:

  1. Use #include in your program to add support for TCHAR.

  2. For strings, such as "abc" is represented by _T("abc") . Is to add _T("").

  3. When defining a character variable, replace char with TCHAR.

  4. The function of the action string should also be replaced with the appropriate TCHAR version, for example, strcpy is to be replaced stcscpy. See MSDN for details.

Method 2: Undefine the macro definition of Unicode encoding in your code so that subsequent compilations are coded with MBCS.

The method is simple, just add the following code to the top of the code file:

#undef UNICODE
#undef _UNICODE

This eliminates the macro definition of Unicode encoding and lets the entire project compile in MBCS encoding.

Method 3: In VC2008, the character encoding in the project properties is modified to MBCS.

Step: Click the menu "Project - xxx Properties...", "Configuration Properties" on the left side of the point, and find"Character Set" in the settings on the right,then modify the default "Use Unicode" Character Set" to"Use Multi-Byte Character Set."

Once set up, compile again to see that the problem has been resolved.

(贡献者:Krissi  编辑