0

I am trying to do the following:

class sig
{
    CComboBox objList;
    void SetDefault();
}
void sig :: SetDefault()
{
    objList.InsertString(0, METHOD_ONE);
}

I have defined METHOD_ONE in a different class as

#define METHOD_ONE "OFF"

And I get the above error.

Can somebody please help me?

Cheers,

Chintan

chintan s
  • 6,170
  • 16
  • 53
  • 86

1 Answers1

3

The most important part is to understand the error; know what is a const char [4], is the easy part but, what about the LPCTSTR?

According to the Microsoft documentation:

An LPCWSTR if UNICODE is defined, an LPCSTR otherwise. For more information, see Windows Data Types for Strings.

And the LPCWSTR is:

A pointer to a constant null-terminated string of 16-bit Unicode characters. For more information, see Character Sets Used By Fonts.

First, you must check out what type of encoding are using your program; it seems that you're using UNICODE, so in the end you're trying to convert a const pointer to chars (the "OFF" constant) to a const pointer to wchar_t, and (logically) the conversion isn't allowed.

Then, you can choose the correct string type; if UNICODE is defined, your #define must be wide string:

// Note the L
#define METHOD_ONE L"OFF"

You can also define it this way:

#ifdef UNICODE
#define METHOD_ONE L"OFF"
#else
#define METHOD_ONE "OFF"
#endif

Or use the _T macro suggested by Roman R. The only that this macro does is to append L prefix to the text:

#ifdef UNICODE
#define _T(x) L ##x
#else
#define _T(x) x
#endif

In the end, you must be aware of what kind of string are using; but Microsoft is hidding it by using an obscure chain of #defines and typedefs.

PaperBirdMaster
  • 12,806
  • 9
  • 48
  • 94