Combining wide string literal with string macro

2019-06-26 17:23发布

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?

1条回答
手持菜刀,她持情操
2楼-- · 2019-06-26 17:50

Did you try

#define APPNAME "MyApp"

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

const wchar_t *AppProgID = WIDEN(APPNAME) L".Document";
查看更多
登录 后发表回答