UNICODE_STRING support functions?

I’ve dug through the documentation on MSDN and the DDK, and searched the
OSR forums, and I can’t seem to find a function that creates a new
UNICODE_STRING and allocates a brand spanking new buffer of a specified
size. I’m really hoping that I’m Google-inept here. It would seem
silly to create the fancy-schmancy RtlUnicodeString functions without
including something as basic as proto-constructor and destructor that
handle the allocation/deallocation and set the Length and MaximumLength
appropriately.

New UNICODE_STRINGS have to come from somewhere, they can’t just
magically poof themselves into existence, and eventually they have to
get freed. Including support for doing this consistently and correctly
would probably go a long way towards stamping out bugs. Would somebody
please clue me in if there are some basic functions that do this?

~Eric

Eric,

There is no function to allocate a UNICODE_STRING Buffer, and set the
Length to zero and the MaximumLength to the size. There are some samples
that provide things, for instance src\filesys\miniFilter\ctx\support.c has
allocate and deallocate functions.

There are functions doing convesions such as
RtlUnicodeStringToAnsiString that will allocate a string buffer for you.
One often overlooked capability is the RTL_CONSTANT_STRING macro that
initializes a UNICODE_STRING to point to a constant wide character string.

Remember many UNICODE_STRING’s point to data that they do not
allocate. One of the real powers of the counted string approach is that
substrings do not need a copy, as they do with the null terminated “C”
string model.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply

“Eric Diven” wrote in message news:xxxxx@ntfsd…
I’ve dug through the documentation on MSDN and the DDK, and searched the
OSR forums, and I can’t seem to find a function that creates a new
UNICODE_STRING and allocates a brand spanking new buffer of a specified
size. I’m really hoping that I’m Google-inept here. It would seem
silly to create the fancy-schmancy RtlUnicodeString functions without
including something as basic as proto-constructor and destructor that
handle the allocation/deallocation and set the Length and MaximumLength
appropriately.

New UNICODE_STRINGS have to come from somewhere, they can’t just
magically poof themselves into existence, and eventually they have to
get freed. Including support for doing this consistently and correctly
would probably go a long way towards stamping out bugs. Would somebody
please clue me in if there are some basic functions that do this?

~Eric

{
UNICODE_STRING MyString;

RtlInitUnicodeString( &MyString,
L"Blah Blah Moo Moo"); //dont dealloc, because static string
}

|-----Original Message-----
|From: xxxxx@lists.osr.com
|[mailto:xxxxx@lists.osr.com] On Behalf Of Don Burn
|Sent: Tuesday, July 31, 2007 9:22 AM
|To: Windows File Systems Devs Interest List
|Subject: Re:[ntfsd] UNICODE_STRING support functions?
|
|Eric,
|
| There is no function to allocate a UNICODE_STRING Buffer,
|and set the Length to zero and the MaximumLength to the size.
|There are some samples that provide things, for instance
|src\filesys\miniFilter\ctx\support.c has allocate and
|deallocate functions.
|
| There are functions doing convesions such as
|RtlUnicodeStringToAnsiString that will allocate a string
|buffer for you.
|One often overlooked capability is the RTL_CONSTANT_STRING
|macro that initializes a UNICODE_STRING to point to a constant
|wide character string.
|
| Remember many UNICODE_STRING’s point to data that they
|do not allocate. One of the real powers of the counted string
|approach is that substrings do not need a copy, as they do
|with the null terminated “C”
|string model.
|
|–
|Don Burn (MVP, Windows DDK)
|Windows 2k/XP/2k3 Filesystem and Driver Consulting
|Website: http://www.windrvr.com
|Blog: http://msmvps.com/blogs/WinDrvr
|Remove StopSpam to reply
|
|
|“Eric Diven” wrote in message
|news:xxxxx@ntfsd…
|I’ve dug through the documentation on MSDN and the DDK, and
|searched the OSR forums, and I can’t seem to find a function
|that creates a new UNICODE_STRING and allocates a brand
|spanking new buffer of a specified size. I’m really hoping
|that I’m Google-inept here. It would seem silly to create the
|fancy-schmancy RtlUnicodeString functions without including
|something as basic as proto-constructor and destructor that
|handle the allocation/deallocation and set the Length and
|MaximumLength appropriately.
|
|New UNICODE_STRINGS have to come from somewhere, they can’t
|just magically poof themselves into existence, and eventually
|they have to get freed. Including support for doing this
|consistently and correctly would probably go a long way
|towards stamping out bugs. Would somebody please clue me in
|if there are some basic functions that do this?
|
|~Eric
|
|
|
|—
|NTDEV is sponsored by OSR
|
|For our schedule debugging and file system seminars (including
|our new fs mini-filter seminar) visit:
|http://www.osr.com/seminars
|
|You are currently subscribed to ntfsd as: xxxxx@lrs.com To
|unsubscribe send a blank email to xxxxx@lists.osr.com
|

“Kozak, Joe” wrote in message news:xxxxx@ntfsd…

{
UNICODE_STRING MyString;

RtlInitUnicodeString( &MyString,
L"Blah Blah Moo Moo"); //dont dealloc, because
static string
}

Yep and 9 times out of 10 you can replace that with,

static UNICODE_STRING MyString =
RTL_CONSTANT_STRING(L"Blah Blah Moo Moo");

saving both space and time. RtlInitUnicodeString is one of the first
things I check for in code, since most of the time it is worthless.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply

|-----Original Message-----
|From: xxxxx@lists.osr.com
|[mailto:xxxxx@lists.osr.com] On Behalf Of Don Burn
|Sent: Tuesday, July 31, 2007 9:22 AM
|To: Windows File Systems Devs Interest List
|Subject: Re:[ntfsd] UNICODE_STRING support functions?
|
|Eric,
|
| There is no function to allocate a UNICODE_STRING Buffer,
|and set the Length to zero and the MaximumLength to the size.
|There are some samples that provide things, for instance
|src\filesys\miniFilter\ctx\support.c has allocate and
|deallocate functions.
|
| There are functions doing convesions such as
|RtlUnicodeStringToAnsiString that will allocate a string
|buffer for you.
|One often overlooked capability is the RTL_CONSTANT_STRING
|macro that initializes a UNICODE_STRING to point to a constant
|wide character string.
|
| Remember many UNICODE_STRING’s point to data that they
|do not allocate. One of the real powers of the counted string
|approach is that substrings do not need a copy, as they do
|with the null terminated “C”
|string model.
|
|–
|Don Burn (MVP, Windows DDK)
|Windows 2k/XP/2k3 Filesystem and Driver Consulting
|Website: http://www.windrvr.com
|Blog: http://msmvps.com/blogs/WinDrvr
|Remove StopSpam to reply
|
|
|“Eric Diven” wrote in message
|news:xxxxx@ntfsd…
|I’ve dug through the documentation on MSDN and the DDK, and
|searched the OSR forums, and I can’t seem to find a function
|that creates a new UNICODE_STRING and allocates a brand
|spanking new buffer of a specified size. I’m really hoping
|that I’m Google-inept here. It would seem silly to create the
|fancy-schmancy RtlUnicodeString functions without including
|something as basic as proto-constructor and destructor that
|handle the allocation/deallocation and set the Length and
|MaximumLength appropriately.
|
|New UNICODE_STRINGS have to come from somewhere, they can’t
|just magically poof themselves into existence, and eventually
|they have to get freed. Including support for doing this
|consistently and correctly would probably go a long way
|towards stamping out bugs. Would somebody please clue me in
|if there are some basic functions that do this?
|
|~Eric
|
|
|
|—
|NTDEV is sponsored by OSR
|
|For our schedule debugging and file system seminars (including
|our new fs mini-filter seminar) visit:
|http://www.osr.com/seminars
|
|You are currently subscribed to ntfsd as: xxxxx@lrs.com To
|unsubscribe send a blank email to xxxxx@lists.osr.com
|

I’ll agree that these are fine solutions for most cases, but I would imagine you’d want your very own buffer sized to your specifications for doing just about any manipulation. Since, as you said, most UNICODE_STRINGS don’t actually point to data that they allocate, nearly any time you want to modify that, I would think it would be wise to do it elsewhere. Consider further the issue of concatenating two strings. Odds are, if they’ve come from “elsewhere” neither is big enough to hold the result of the concatenation even if it were kosher to modify it. You’re stuck making a new string anyway, so why not have the support to do so conveniently included in the library.

I looked at the code Don referred to, and it’s basically what I would have written to do the same. It’s certainly trivial enough code, but sooner or later, somebody is bound to screw it up and introduce a bug. Potentially a tricky one to find at that, if they don’t initialize MaximumLength at all.

Thanks for tipping me off to the RTL_CONSTANT_STRING macro, that’s pretty handy (and a lot handier than calling the function).

~Eric

What are the pitfalls of RtlInitUnicodeString() too look out for.

|-----Original Message-----
|From: xxxxx@lists.osr.com
|[mailto:xxxxx@lists.osr.com] On Behalf Of Don Burn
|Sent: Tuesday, July 31, 2007 10:20 AM
|To: Windows File Systems Devs Interest List
|Subject: Re:[ntfsd] Re:UNICODE_STRING support functions?
|
|
|“Kozak, Joe” wrote in message
|news:xxxxx@ntfsd…
|
|{
|UNICODE_STRING MyString;
|
| RtlInitUnicodeString( &MyString,
| L"Blah Blah Moo Moo"); //dont
|dealloc, because static string }
|
|Yep and 9 times out of 10 you can replace that with,
|
|static UNICODE_STRING MyString =
| RTL_CONSTANT_STRING(L"Blah Blah Moo Moo");
|
|saving both space and time. RtlInitUnicodeString is one of the first
|things I check for in code, since most of the time it is worthless.
|
|
|–
|Don Burn (MVP, Windows DDK)
|Windows 2k/XP/2k3 Filesystem and Driver Consulting
|Website: http://www.windrvr.com
|Blog: http://msmvps.com/blogs/WinDrvr
|Remove StopSpam to reply
|
||-----Original Message-----
||From: xxxxx@lists.osr.com
||[mailto:xxxxx@lists.osr.com] On Behalf Of Don Burn
||Sent: Tuesday, July 31, 2007 9:22 AM
||To: Windows File Systems Devs Interest List
||Subject: Re:[ntfsd] UNICODE_STRING support functions?
||
||Eric,
||
|| There is no function to allocate a UNICODE_STRING
|Buffer, and set
||the Length to zero and the MaximumLength to the size.
||There are some samples that provide things, for instance
||src\filesys\miniFilter\ctx\support.c has allocate and deallocate
||functions.
||
|| There are functions doing convesions such as
||RtlUnicodeStringToAnsiString that will allocate a string buffer for
||you.
||One often overlooked capability is the RTL_CONSTANT_STRING macro that
||initializes a UNICODE_STRING to point to a constant wide character
||string.
||
|| Remember many UNICODE_STRING’s point to data that they do not
||allocate. One of the real powers of the counted string approach is
||that substrings do not need a copy, as they do with the null
|terminated
||“C”
||string model.
||
||–
||Don Burn (MVP, Windows DDK)
||Windows 2k/XP/2k3 Filesystem and Driver Consulting
||Website: http://www.windrvr.com
||Blog: http://msmvps.com/blogs/WinDrvr
||Remove StopSpam to reply
||
||
||“Eric Diven” wrote in message
||news:xxxxx@ntfsd…
||I’ve dug through the documentation on MSDN and the DDK, and searched
||the OSR forums, and I can’t seem to find a function that
|creates a new
||UNICODE_STRING and allocates a brand spanking new buffer of a
|specified
||size. I’m really hoping that I’m Google-inept here. It would seem
||silly to create the fancy-schmancy RtlUnicodeString functions without
||including something as basic as proto-constructor and destructor that
||handle the allocation/deallocation and set the Length and
|MaximumLength
||appropriately.
||
||New UNICODE_STRINGS have to come from somewhere, they can’t just
||magically poof themselves into existence, and eventually they have to
||get freed. Including support for doing this consistently and
|correctly
||would probably go a long way towards stamping out bugs.
|Would somebody
||please clue me in if there are some basic functions that do this?
||
||~Eric
||
||
||
||—
||NTDEV is sponsored by OSR
||
||For our schedule debugging and file system seminars
|(including our new
||fs mini-filter seminar) visit:
||http://www.osr.com/seminars
||
||You are currently subscribed to ntfsd as: xxxxx@lrs.com To
||unsubscribe send a blank email to xxxxx@lists.osr.com
||
|
|
|
|—
|NTDEV is sponsored by OSR
|
|For our schedule debugging and file system seminars (including
|our new fs mini-filter seminar) visit:
|http://www.osr.com/seminars
|
|You are currently subscribed to ntfsd as: xxxxx@lrs.com
|To unsubscribe send a blank email to xxxxx@lists.osr.com
|

It is not that it has pitfalls persea, but if you miss doing it before
using the string you are in trouble. Second, it is out there doing a
strlen (never a great function, think of what happens if there is no null)
and runing code for your driver, when the compiler can do it for you.
Personally, I will always choose to do things at compile time when
reasonable, versus doing the same thing at runtime.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply

“Kozak, Joe” wrote in message news:xxxxx@ntfsd…
What are the pitfalls of RtlInitUnicodeString() too look out for.

|-----Original Message-----
|From: xxxxx@lists.osr.com
|[mailto:xxxxx@lists.osr.com] On Behalf Of Don Burn
|Sent: Tuesday, July 31, 2007 10:20 AM
|To: Windows File Systems Devs Interest List
|Subject: Re:[ntfsd] Re:UNICODE_STRING support functions?
|
|
|“Kozak, Joe” wrote in message
|news:xxxxx@ntfsd…
|
|{
|UNICODE_STRING MyString;
|
| RtlInitUnicodeString( &MyString,
| L"Blah Blah Moo Moo"); //dont
|dealloc, because static string }
|
|Yep and 9 times out of 10 you can replace that with,
|
|static UNICODE_STRING MyString =
| RTL_CONSTANT_STRING(L"Blah Blah Moo Moo");
|
|saving both space and time. RtlInitUnicodeString is one of the first
|things I check for in code, since most of the time it is worthless.
|
|
|–
|Don Burn (MVP, Windows DDK)
|Windows 2k/XP/2k3 Filesystem and Driver Consulting
|Website: http://www.windrvr.com
|Blog: http://msmvps.com/blogs/WinDrvr
|Remove StopSpam to reply
|
||-----Original Message-----
||From: xxxxx@lists.osr.com
||[mailto:xxxxx@lists.osr.com] On Behalf Of Don Burn
||Sent: Tuesday, July 31, 2007 9:22 AM
||To: Windows File Systems Devs Interest List
||Subject: Re:[ntfsd] UNICODE_STRING support functions?
||
||Eric,
||
|| There is no function to allocate a UNICODE_STRING
|Buffer, and set
||the Length to zero and the MaximumLength to the size.
||There are some samples that provide things, for instance
||src\filesys\miniFilter\ctx\support.c has allocate and deallocate
||functions.
||
|| There are functions doing convesions such as
||RtlUnicodeStringToAnsiString that will allocate a string buffer for
||you.
||One often overlooked capability is the RTL_CONSTANT_STRING macro that
||initializes a UNICODE_STRING to point to a constant wide character
||string.
||
|| Remember many UNICODE_STRING’s point to data that they do not
||allocate. One of the real powers of the counted string approach is
||that substrings do not need a copy, as they do with the null
|terminated
||“C”
||string model.
||
||–
||Don Burn (MVP, Windows DDK)
||Windows 2k/XP/2k3 Filesystem and Driver Consulting
||Website: http://www.windrvr.com
||Blog: http://msmvps.com/blogs/WinDrvr
||Remove StopSpam to reply
||
||
||“Eric Diven” wrote in message
||news:xxxxx@ntfsd…
||I’ve dug through the documentation on MSDN and the DDK, and searched
||the OSR forums, and I can’t seem to find a function that
|creates a new
||UNICODE_STRING and allocates a brand spanking new buffer of a
|specified
||size. I’m really hoping that I’m Google-inept here. It would seem
||silly to create the fancy-schmancy RtlUnicodeString functions without
||including something as basic as proto-constructor and destructor that
||handle the allocation/deallocation and set the Length and
|MaximumLength
||appropriately.
||
||New UNICODE_STRINGS have to come from somewhere, they can’t just
||magically poof themselves into existence, and eventually they have to
||get freed. Including support for doing this consistently and
|correctly
||would probably go a long way towards stamping out bugs.
|Would somebody
||please clue me in if there are some basic functions that do this?
||
||~Eric
||
||
||
||—
||NTDEV is sponsored by OSR
||
||For our schedule debugging and file system seminars
|(including our new
||fs mini-filter seminar) visit:
||http://www.osr.com/seminars
||
||You are currently subscribed to ntfsd as: xxxxx@lrs.com To
||unsubscribe send a blank email to xxxxx@lists.osr.com
||
|
|
|
|—
|NTDEV is sponsored by OSR
|
|For our schedule debugging and file system seminars (including
|our new fs mini-filter seminar) visit:
|http://www.osr.com/seminars
|
|You are currently subscribed to ntfsd as: xxxxx@lrs.com
|To unsubscribe send a blank email to xxxxx@lists.osr.com
|