views:

315

answers:

1

I have a macro for a character string as follows:

#define APPNAME "MyApp"

Now I want to construct a wide string using this macro by doing something like:

const wchar_t *AppProgID = APPNAME L".Document";

However, this generates a "concatenating mismatched strings" compilation error.

Is there a way to convert the APPNAME macro to a wide string literal?

+3  A: 

Did you try

#define APPNAME "MyApp"

#define WIDEN2(x) L ## x
#define WIDEN(x) WIDEN2(x)

const wchar_t *AppProgID = WIDEN(APPNAME) L".Document";
Marcel Gosselin
Yes, but I was wondering if there was a way of doing this without having to define two versions of the macro (wide and non-wide).
flashk
Works like a charm, thanks!
flashk
I've updated my answer to have use some common preprocessor technique to deal with strings. You can see more advanced usages if you peek at http://www.boost.org/doc/libs/1_40_0/libs/preprocessor/doc/index.html
Marcel Gosselin