1

In my application I want to add the version ID as a macro and use it in multiple parts of the application. As explained in this question I can easily generate a string with this:

#define APP_VER "1.0"
#define APP_CAPTION "Stackoverflow example app v." ## APP_VER

My problem is now, that in some parts, I need to have the caption as an unicode string.

I tried the following:

MessageBoxW(0,_T(APP_CAPTION),L"Minimal Counterexample",0);

But it gives the error "can't concernate wide 'Stackoverflow example app v.' with narrow '1.0'"

I also tried

#define WIDE_CAPTION L ## APP_CAPTION

But that just gives "LAPP_CAPTION" is not defined.

I know that I can convert the string at runtime to unicode, but that is rather messy. Can someone provide a Macro-level solution for my problem?

Community
  • 1
  • 1
Listing
  • 1,171
  • 2
  • 15
  • 31

1 Answers1

2

You just want:

#define APP_CAPTION "Stackoverflow example app v." APP_VER

Since APP_VER is already a string.

String concatenation happens for free, for example:

const char *str = "hello " "world"

Complete compilable example:

#include <iostream>
#define APP_VER "1.0"
#define APP_CAPTION "Stackoverflow example app v." APP_VER

int main() {
  std::cout << APP_CAPTION << "\n";
  return 0;
}
Flexo
  • 87,323
  • 22
  • 191
  • 272
  • 1
    I see that the '##' can be left out, but it doesn't fix my initial problem. – Listing Aug 14 '12 at 18:18
  • I figured it out myself, it has to be ' #define APP_CAPTION L"Stackoverflow example app v." _T(APP_VER) ' – Listing Aug 14 '12 at 18:28
  • 5
    @Listing If you are using the `_T` macro, why are you using `L"..."` and the *W*ide version of functions? Try to keep consistency or you will be maintaining a mess. – Marlon Aug 14 '12 at 18:35
  • 1
    Indeed, it should be `#define APP_CAPTION _T("Stack Overflow example app v." _T(APP_VER)` – Cody Gray - on strike Aug 14 '12 at 19:34