Reputation: 11
In Windows driver C code, I need to set a WCHAR array to a string that is #defined in a header file. The header file specifies an ascii string. It does not specify the L prefix for the string.
// In the header file
#define VERS_STR "3.2.4"
// In the C file, none of the following work
WCHAR awcStr[] = LVERS_STR; // Compiler Error: Treated as one name
WCHAR awcStr[] = L VERS_STR; // Compiler Error: L is unknown
WCHAR awcStr[] = L(VERS_STR); // Compiler Error
WCHAR awcStr[] = L"3.2.4"; // Compiles and runs, but I must use #define instead
I would call a conversion routine on the #define, but I can't find one that I can call from a Windows driver using C code.
Upvotes: 0
Views: 233
Reputation: 177901
A WIDE macro might exist, but I’m not where I can check easily, but this sequence implements it:
#define WIDE2(x) L##x
#define WIDE1(x) WIDE2(x)
#define WIDE(x) WIDE1(x)
Due to how macros work, WIDE1 will expand your macro, and WIDE2 will add the L with the concatenation macro operator. Just call WIDE(VERS_STR)
.
Upvotes: 2