0

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.

Louie
  • 11
  • 2

1 Answers1

2

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).

Mark Tolonen
  • 166,664
  • 26
  • 169
  • 251
  • That got me started in the right direction. It requires 2 levels of macros to have the pre-processor treat things the way I need them. – Louie Apr 22 '19 at 16:35
  • I just added the #defines in my file which worked fine, but is there a standard Windows/C include file with these macros? I could not find it. – Louie Apr 22 '19 at 16:41