在 C 中使用 PCWSTR

Using a PCWSTR in C

我正在尝试在 C 中使用 PCWSTR(使用 Windows XP Free Build Env w/DDK 编译)(我知道这是旧的),我似乎不明白如何获得字符串工作。

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

得到以下内容

 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]'

我做错了什么?

在旧版本的 C 中,声明需要出现在块中任何 non-declarations 之前。

所以

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

不允许,但是

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

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

允许在块的开头。