Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Using a PCWSTR in C

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading