I have a Unicode Win32 application that uses 3rd party libraries, some of which provide constants for their version information as #defined (narrow) strings. For instance, libpng has the following:
#define PNG_LIBPNG_VER_STRING "1.5.4"
#define PNG_HEADER_VERSION_STRING \
" libpng version 1.5.4 - July 7, 2011\n"
I'm appending the various statically linked libraries version information to my About Box for easy version tracking, and it seemed like it would be simple to convert this constant into a wide string.
My first attempt was TEXT(PNG_HEADER_VERSION_STRING), but that fails as
#define __TEXT(quote) L##quote
.. and LPNGHEADER_VERSION_STRING doesn't exist of course.
So I tried several combinations of double wrapping macros, and all sorts of ## tricks to attempt to add the L prefix to a macro'ed constant, but wasn't able to. Am I missing something simple? How would you handle:
#define VERSIONSTR "Test V1.2.3"
const char* ver= VERSIONSTR;
const wchar* wver = _T(VERSIONSTR); // fails, should be L"Test V1.2.3"
#define VERSIONSTRW _T(VERSIONSTR); // fails also
programmatically, without simply adding a duplicate L"Test V1.2.3" and having to keep it in sync with the 3rd party library.
I know I can just convert it at runtime if I'm building for Unicode, but I thought surely there was a quick way to re-define this constant.
---UPDATE---
I missed the plot by doing something really stupid with my include structure. Fixing that allowed the double define wrapper to function as it should. Stupid on my part.
#define VERSIONSTRW _T(VERSIONSTR)
works for me in VC++ 2008. – Selfcontent