I am new to driver programming, and for sometime now I (mis)assumed that
PUNICODE_STRING is same as LPCWSTR, and even my debug statements which cast
PUNICODE_STRING to LPCWSTR worked. Now that I know they are different, if
there is an equivalent of RtlInitUnicodeString that gives me a pointer to a
copy of the buffer the unicode-string points to. Note that I am inclined not
to use UnicodeString->Buffer directly as that need not be null terminated.
Does such a function exist in the DDK? Thanks.
After you have a LPCWSTR, what are you going to do with it? The reason
I ask is that there may not be a need to do the conversion in the first
place. For instance, in the server sp1 version of ntstrsafe.h has
UNICODE_STRING equivalents for all the functions previously only
available for null terminated strings.
For debug prints, you can use %wZ as the format specifier to print out
PUNICODE_STRINGs. There is no equivalent Rtl function which creates a
null terminated string from a PUNICODE_STRING. On the other hand,
rolling your own is super easy, it’s a malloc, copy and null terminate.
d
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of F Lace
Sent: Monday, August 29, 2005 11:08 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] UNICODE_STRING to LPCWSTR
I am new to driver programming, and for sometime now I (mis)assumed that
PUNICODE_STRING is same as LPCWSTR, and even my debug statements which
cast PUNICODE_STRING to LPCWSTR worked. Now that I know they are
different, if there is an equivalent of RtlInitUnicodeString that gives
me a pointer to a copy of the buffer the unicode-string points to. Note
that I am inclined not to use UnicodeString->Buffer directly as that
need not be null terminated. Does such a function exist in the DDK?
Thanks. — Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256 You are currently subscribed
to ntdev as: unknown lmsubst tag argument: ‘’ To unsubscribe send a
blank email to xxxxx@lists.osr.com
Absolutely not so.
PWSTR is guaranteed to be zero-terminated, while UNICODE_STRING has no such guarantee. You will have a crash sometimes when you will have this kind of UNICODE_STRING.
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com
----- Original Message -----
From: F Lace
To: Windows System Software Devs Interest List
Sent: Tuesday, August 30, 2005 10:08 AM
Subject: [ntdev] UNICODE_STRING to LPCWSTR
I am new to driver programming, and for sometime now I (mis)assumed that PUNICODE_STRING is same as LPCWSTR, and even my debug statements which cast PUNICODE_STRING to LPCWSTR worked. Now that I know they are different, if there is an equivalent of RtlInitUnicodeString that gives me a pointer to a copy of the buffer the unicode-string points to. Note that I am inclined not to use UnicodeString->Buffer directly as that need not be null terminated. Does such a function exist in the DDK? Thanks. — Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256 You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’ To unsubscribe send a blank email to xxxxx@lists.osr.com
On 8/30/05, Maxim S. Shatskih wrote:
>
> Absolutely not so.
> PWSTR is guaranteed to be zero-terminated, while UNICODE_STRING has no
> such guarantee. You will have a crash sometimes when you will have this kind
> of UNICODE_STRING.
>
What are you trying to say here, it is not clear to me. I know the Buffer
in UNICODE_STRING is not null terminated, that is why I was wondering how to
make a PWSTR out of it as I need to save it to other data structure for some
purpose. Looks like most of the DDK routines take PUNICODE_STRING itself,
and for my purpose I wrote a function myself to obtain a null terminated
PWSTR.
Thanks.
What was being asked is, why do you want a PWSTR? If you are doing the work
of the conversion, there must be a reason you think you need it. Note, over
the last few years there has been a major effort to eliminate the use of
standard null-terminated string fuctions, people either use safestring since
they have a null terminated string, or counted strings like UNICODE_STRING
since they are more efficient.
–
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Remove StopSpam from the email to reply
“F Lace” wrote in message news:xxxxx@ntdev…
On 8/30/05, Maxim S. Shatskih wrote:
>
> Absolutely not so.
> PWSTR is guaranteed to be zero-terminated, while UNICODE_STRING has no
> such guarantee. You will have a crash sometimes when you will have this
> kind
> of UNICODE_STRING.
>
What are you trying to say here, it is not clear to me. I know the Buffer
in UNICODE_STRING is not null terminated, that is why I was wondering how to
make a PWSTR out of it as I need to save it to other data structure for some
purpose. Looks like most of the DDK routines take PUNICODE_STRING itself,
and for my purpose I wrote a function myself to obtain a null terminated
PWSTR.
Thanks.
The buffer in UNICODE_STRING may or may not be zero terminated. It is your
choice. If the size of the buffer is larger than the size of the string,
appending a zero/NUL/EOS is easy. If you are so dependent upon PWSTR types
you are probably using the unsafe string functions and intrinsics. Read
about the safe string functions and I believe that wd-3.com had an article
on their use.
“F Lace” wrote in message news:xxxxx@ntdev…
On 8/30/05, Maxim S. Shatskih wrote:
>
> Absolutely not so.
> PWSTR is guaranteed to be zero-terminated, while UNICODE_STRING has no
> such guarantee. You will have a crash sometimes when you will have this
> kind
> of UNICODE_STRING.
>
What are you trying to say here, it is not clear to me. I know the Buffer
in UNICODE_STRING is not null terminated, that is why I was wondering how to
make a PWSTR out of it as I need to save it to other data structure for some
purpose. Looks like most of the DDK routines take PUNICODE_STRING itself,
and for my purpose I wrote a function myself to obtain a null terminated
PWSTR.
Thanks.
On 8/30/05, Don Burn wrote:
>
> What was being asked is, why do you want a PWSTR? If you are doing the
> work
> of the conversion, there must be a reason you think you need it. Note,
> over
> the last few years there has been a major effort to eliminate the use of
> standard null-terminated string fuctions, people either use safestring
> since
> they have a null terminated string, or counted strings like UNICODE_STRING
> since they are more efficient.
I realize the advantages of counted strings, I want to use PWSTR only to
leverage the library I have for several data structures. Going forward I
intend to incorporate UNICODE_STRING in my library.
.
For debug prints, you can use %wZ as the format specifier to print out
PUNICODE_STRINGs.
Is there an sprintf equivalent to combine multiple UNICODE_STRINGS into
one?
%wZ should work for sprintf as well. ?If you are going to use a printf variant, please use the ntstrsafe.h version of it, which will guarantee that you will not overflow the string being formatted.
d
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of F Lace
Sent: Tuesday, August 30, 2005 10:47 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] UNICODE_STRING to LPCWSTR
.
For debug prints, you can use %wZ as the format specifier to print out
PUNICODE_STRINGs.??
?
?
?
Is there an sprintf equivalent to combine multiple UNICODE_STRINGS into one?
?
— Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256 You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’ To unsubscribe send a blank email to xxxxx@lists.osr.com
On 8/30/05, Doron Holan wrote:
> After you have a LPCWSTR, what are you going to do with it? The reason
> I ask is that there may not be a need to do the conversion in the first
> place. For instance, in the server sp1 version of ntstrsafe.h has
> UNICODE_STRING equivalents for all the functions previously only
> available for null terminated strings.
>
1. I downloaded server sp1 ddk (3790.1830). Although I find
RtlUnicodeString* functions in ntstrsafe.h, the documentation does not
seem to say anything about them and none of the samples seem to use
RtlUnicodeString* functions. Should I be just looking at the
ntstrsafe.h header file for details, or does documentation and samples
exist somewhere online?
2. I am using VC6 compiler and documentation suggests I should be
using strsafe.h instead of ntstrsafe.h in my user mode app. I am
currently using Feb2003 PSDK and its strsafe.h doesnt seem to define
RtlUnicodeString* functions. Before I download April2005 PSDK, can
someone confirm that strsafe.h in this PSDK has RtlUnicodeString
functions?
3. Although the Rtl functions cover the basic string operations, I
coudl not find the Rtl equivalents of the following str functions .
They might be trivial to implement, I am wondering why Microsoft has
not implemented them.
- strncmp - RtlCompareUnicodeString equivalent that the number of
chars to compare
- strstr - search function equivalent
Thanks.
RtlUnicodeString* APIs only exist in ntstrsafe.h. User mode code does
not use UNICODE_STRING so it didn’t make sense to put it into strsafe.h.
These were added to the server release after the docs were complete, you
will not find docs for it until the WDK is released. A general rule of
thumb is to look at the RtlStringX documentation and it will apply to
RtlUnicodeX directly, only the dest parameter changes.
Strstr/strncmp exist in KM (as do their wcs equivalents). Why are there
no UNICODE_STRING versions of these? Well, there was no need, no one
has asked for them. Why are there no string safe versions of these?
Because the probably of a buffer overrun doesn’t exist. Both of these
just search through a null terminated string, none of them write to a
buffer. Writing to a buffer w/out knowing its length (ie most CRT str
functions) is what can cause a buffer overrun.
d
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of F Lace
Sent: Thursday, September 01, 2005 10:13 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] UNICODE_STRING to LPCWSTR
On 8/30/05, Doron Holan wrote:
> After you have a LPCWSTR, what are you going to do with it? The
reason
> I ask is that there may not be a need to do the conversion in the
first
> place. For instance, in the server sp1 version of ntstrsafe.h has
> UNICODE_STRING equivalents for all the functions previously only
> available for null terminated strings.
>
1. I downloaded server sp1 ddk (3790.1830). Although I find
RtlUnicodeString* functions in ntstrsafe.h, the documentation does not
seem to say anything about them and none of the samples seem to use
RtlUnicodeString* functions. Should I be just looking at the
ntstrsafe.h header file for details, or does documentation and samples
exist somewhere online?
2. I am using VC6 compiler and documentation suggests I should be
using strsafe.h instead of ntstrsafe.h in my user mode app. I am
currently using Feb2003 PSDK and its strsafe.h doesnt seem to define
RtlUnicodeString* functions. Before I download April2005 PSDK, can
someone confirm that strsafe.h in this PSDK has RtlUnicodeString
functions?
3. Although the Rtl functions cover the basic string operations, I
coudl not find the Rtl equivalents of the following str functions .
They might be trivial to implement, I am wondering why Microsoft has
not implemented them.
- strncmp - RtlCompareUnicodeString equivalent that the number of
chars to compare
- strstr - search function equivalent
Thanks.
—
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
You are currently subscribed to ntdev as: unknown lmsubst tag argument:
‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com
On 9/2/05, Doron Holan wrote:
> RtlUnicodeString* APIs only exist in ntstrsafe.h. User mode code does
> not use UNICODE_STRING so it didn’t make sense to put it into strsafe.h.
Thanks for the explanation. Why is it that user mode code does not use
UNICODE_STRING? I am trying to write a library that will be used both
in kernel mode and user mode, and I wanted to use UNICODE_STRINGs in
the library. It is not clear why the advantages of UNICODE_STRING over
PWSTR cannot be leveraged in user mode.
Thanks.
There is nothing stopping you from using UNICODE_STRINGs in UM. There
is no use for them because no Win32 or CR API takes one as a parameter.
d
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of F Lace
Sent: Thursday, September 01, 2005 11:12 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] UNICODE_STRING to LPCWSTR
On 9/2/05, Doron Holan wrote:
> RtlUnicodeString* APIs only exist in ntstrsafe.h. User mode code does
> not use UNICODE_STRING so it didn’t make sense to put it into
strsafe.h.
Thanks for the explanation. Why is it that user mode code does not use
UNICODE_STRING? I am trying to write a library that will be used both
in kernel mode and user mode, and I wanted to use UNICODE_STRINGs in
the library. It is not clear why the advantages of UNICODE_STRING over
PWSTR cannot be leveraged in user mode.
Thanks.
—
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
You are currently subscribed to ntdev as: unknown lmsubst tag argument:
‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com