Home > Net >  Using a PCWSTR in C
Using a PCWSTR in C

Time:04-25

I'm attempting to use PCWSTR in C (Compiled with Windows XP Free Build Env w/ DDK) (i know this is old), and I don't seem to understand how to get a string working.

hKey = NULL;
PCWSTR str = L"test";

gets me the following

 error C2275: 'PCWSTR' : illegal use of this type as an expression
 error C2146: syntax error : missing ';' before identifier 'a'
 error C2144: syntax error : '<Unknown>' should be preceded by '<Unknown>'
 error C2144: syntax error : '<Unknown>' should be preceded by '<Unknown>'
 error C2143: syntax error : missing ';' before 'identifier'
 error C2065: 'a' : undeclared identifier
 error C4047: '=' : 'int' differs in levels of indirection from 'unsigned short [8]'

what am I doing wrong?

CodePudding user response:

In older versions of C, declarations needed to appear before any non-declarations in a block.

So

hKey = NULL;
PCWSTR str = L"test";

would not be allowed, but

PCWSTR str;
hKey = NULL;
str = L"test";

and

PCWSTR str = L"test";
hKey = NULL;

would be allowed at the start of a block.

  • Related