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

Description of the error:

Some programs run well under VC6, but compile under VC2008 and later VCs that report errors (the following is only vc2008, for example, high-version VC-like), for example, 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, you can encounter similar problems 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 problems.

Vc6 uses the MBCS code by default, while VC2008 and high-version VCs use the Unicode encoding by default. Here's a detailed explanation of this:

When using char for characters, English takes up one byte, Chinese takes up two bytes. This has a serious question: are two consecutive bytes, two English characters, or a Chinese character? To solve this problem, Unicode coding was born. Unicode encoding is represented in two bytes, regardless of Chinese English.

For MBCS encoding, character variables are defined with char.
n Unicode encoding, character variables are defined with wchar_t.

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

Most string pointers in the Windows API and EasyX use the LPCTSTR or LPTSTR type, and LPCTSTR/LPTSTR is short for "Long Point (Const) Tchar STRing". So it can be argued that LPCTSTR is const TCHAR and LPTSTR is TCHAR.

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


There are multiple solutions, the same purpose is to match the character encoding.

Method 1: Modify all strings to the TCHAR version.

In simple terms, there are a few things to keep in mind:

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

In simple terms, there are a few things to keep in mind:

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 with the 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 allows the macro definition of Unicode encoding to be dedefined and the entire project to be compiled with MBCS encoding.

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

Step: Dot menu "Project - xxx Properties...", "Configuration Properties" on the left, "Character Set" in the settings on the right, modify the default "Use Unicode" Character Set" is "Use Multi-Byte Character Set."

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