include WInNT.h but fail to declare PTSTR type variable

According to MSDN of visual studio 2008, PTSTR is a windows data type defined in WinNT.h header file.

in my simple program, i include this header file and declare a variable of this type. when i run the program, i received these errors:

1>c:\program files\microsoft sdks\windows\v6.0a\include\winnt.h(296) : error C2146: syntax error : missing ';' before identifier 'WCHAR'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winnt.h(296) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft sdks\windows\v6.0a\include\winnt.h(299) : error C2143: syntax error : missing ';' before '*'

I tried to find solution from microsoft forum and found out that by replacing WinNT.h with windows.h, the problem will be solved, and yes it works for me too.

So what i want to know is the reason behind this fix.


Thanks
mrpc_cambodiaAsked:
Who is Participating?
 
LordOfPortsCommented:
Looking at the Win32 data types http://msdn.microsoft.com/en-us/library/aa383751(VS.85).aspx it states that PWSTR is declared in WinNT.h and CONST in WinDef.h. You are also right, on the Win32 data types web page above it states that WCHAR is declared in the WinNT.h header file but on the WCHAR page http://msdn.microsoft.com/en-us/library/ms684497(VS.85).aspx it states that it is declared in the Esent.h file so it looks like there were design changes from version to version but in either case the error you had been experiencing prior to replacing WinNT.h with Windows.h is related to the inclusion of the files that declared a Win32 data type used in the code.

Looking at http://en.wikipedia.org/wiki/Windows.h it lists the files included by Windows.h and there WinDef.h, which contains the declaration for CONST, is listed as being included prior to WinNT.h.
0
 
mjoachiamiakCommented:
The reason is that you had old version of SDK on your machine. Do you have older version of Visual studio installed?
0
 
mrpc_cambodiaAuthor Commented:
I have visual studio 6, but i only installed vb6 language. does it cause conflict?
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
mjoachiamiakCommented:
No it's not a problem then. Sorry, you give to less points for this question. Please consider increasing the points. It really takes time and the sun is shining outside :). Good luck.
0
 
LordOfPortsCommented:
See the error C2146 http://msdn.microsoft.com/en-us/library/9xbcaa9t(VS.80).aspx indicates WCHAR data type is not recognized it thinks WCHAR is an identifier and not a data type. WCHAR http://msdn.microsoft.com/en-us/library/ms684497(VS.85).aspx is declared in Esent.h which the old version of WinNT.h that you have probably did not include while Windows.h did, indirectly, so once you included Windows.h it ended up including the declaration for WCHAR and then the compiler recognized it.
0
 
mrpc_cambodiaAuthor Commented:
Thanks everyone for your comment,

LordOfPorts, i think you're almost right. with your suggestion it leads me to find out that actually WCHAR is defined in WinNT.h but it's not this identifier that cause problem. instead it's the CONST identifier that is used in WinNT.h but is not declared anywhere within the header file.

to sum it up, i think WinNT.h is not the right header to include if i want to use PWSTR identifier.

Further comments from you all is greatly appreciated. and yes, mjoachiamiak, i will increase more points to encourage more involvement from you all.

Have a good day.
0
 
mjoachiamiakCommented:
What type is your application? Why you don't include standard headers? Or do  you?
I mean: #include "stdafx.h"
0
 
mrpc_cambodiaAuthor Commented:
Am just trying to play around with the windows defined data type. and because the documentation said PWSTR is declared in WinNT.h, that leads me to think that the inclusion of this header is enough to use this data type.

Ok, it's clear now, thank you all.

Enjoy your day.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.