Discussion:
What is a PTSTR?
(too old to reply)
Dale L
2004-02-20 22:43:01 UTC
Permalink
For a long time I've seen PTSTR in Petzold and just figured it was a
pointer to a string. But I got curious and searched (grep) for PTSTR
in all the include files and the only place I see PTSTR defined is in
WINNT.H. So just what is a PTSTR and why would Petzold use it instead
of another data type. Isn't there a compatible "non"-NT data type?

Thanks,
Dale L
Norman Bullen
2004-02-21 01:18:50 UTC
Permalink
Post by Dale L
For a long time I've seen PTSTR in Petzold and just figured it was a
pointer to a string. But I got curious and searched (grep) for PTSTR
in all the include files and the only place I see PTSTR defined is in
WINNT.H. So just what is a PTSTR and why would Petzold use it instead
of another data type. Isn't there a compatible "non"-NT data type?
Thanks,
Dale L
Without knowing in which section of Petzold you found this, and what
he's trying to illustrate in that section, it's hard to say why he chose
to use PTSTR. Even if I did know... Well, let's just say that Petzold
and I have a number of differences of opinion about his examples.

However, let me point out that PSTR is the same thing as LPSTR and LPSTR
is found all over the place in the Windows header files, not just for
NT. Since the advent of Win32 (Windows 95 and NT 3.5) there is only one
size of pointer (32 bits) and most people use the LP... form of the name.

The "T" in the name indicates that this is a pointer to a string that
may be either Ansi or Unicode, depending upon the compile-time variable
UNICODE. Most Unicode APIs are supported only in Windows NT and
descendants so perhaps (if this section of the book deals with Unicode)
Petzold assumes you will be compiling for NT.

Norm
Dale L
2004-02-21 05:45:48 UTC
Permalink
Ahah! After reading yours and Craigs response below... I'll bet a
PTSTR is a pointer to a TCHAR string. What do you think?

Dale L

On Sat, 21 Feb 2004 01:18:50 GMT, Norman Bullen
Post by Norman Bullen
Without knowing in which section of Petzold you found this, and what
he's trying to illustrate in that section, it's hard to say why he chose
to use PTSTR. Even if I did know... Well, let's just say that Petzold
and I have a number of differences of opinion about his examples.
However, let me point out that PSTR is the same thing as LPSTR and LPSTR
is found all over the place in the Windows header files, not just for
NT. Since the advent of Win32 (Windows 95 and NT 3.5) there is only one
size of pointer (32 bits) and most people use the LP... form of the name.
The "T" in the name indicates that this is a pointer to a string that
may be either Ansi or Unicode, depending upon the compile-time variable
UNICODE. Most Unicode APIs are supported only in Windows NT and
descendants so perhaps (if this section of the book deals with Unicode)
Petzold assumes you will be compiling for NT.
Norm
Craig Kelly
2004-02-21 01:26:23 UTC
Permalink
Post by Dale L
For a long time I've seen PTSTR in Petzold and just figured it was a
pointer to a string. But I got curious and searched (grep) for PTSTR
in all the include files and the only place I see PTSTR defined is in
WINNT.H. So just what is a PTSTR and why would Petzold use it instead
of another data type. Isn't there a compatible "non"-NT data type?
Thanks,
Dale L
Dale,

Prepend an L and you'll get all kinds of hits: LPTSTR is all over the place.
The "L" is an artifact of the 16-bit and 32-bit versions of Windows
coexisting. Basically, you're correct; however...

An LPSTR is a pointer to an ANSI string (somtimes called MBCS) and would be
declared char*. LPWSTR is a pointer to a Unicode string and would be
declared wchar_t*. LPTSTR is the fun one... its definition is controlled by
a declare so that you can use a single code base to call the ANSI or Unicode
versions of various Win32 API functions. Many Win32 API functions actually
have a "A" or "W" suffix and have parameters of type LPSTR or LPWSTR: the
same define that changes the type of LPTSTR changes which function you call.

A further note: a "C" in the type name (e.g. LPTCSTR) means it's const...

There's a lot of info on this is MSDN. Also, I'm sure my brief explanation
left some gaping holes that someone will correct :)

Craig
Continue reading on narkive:
Loading...