I scanned the replies and didn’t see any mention of this so I’ll throw this
in since you state you’re seeing garbage characters:
Unicode strings are not guaranteed to be null terminated. In fact, in my
experience, most of them aren’t and it really depends on where they’re
coming from. This is especially true if you’re reading strings from the
registry.
The best way to handle this is to allocate a buffer that is equal to the
source UNICODE_STRING ‘Length’ field plus sizeof(WCHAR). Then copy ‘Length’
bytes from the Unicode string ‘Buffer’ to your WCHAR buffer (after you’ve
zeroed out your buffer or set the last WCHAR to nil).
If you are putting this in your own UNICODE_STRING variable, set ‘Buffer’
equal to your allocated buffer, ‘Length’ to the ‘Length’ from the source
Unicode string and ‘MaximumLength’ to the allocation size of your buffer.
This means that ‘MaximumLength’ will be two bytes longer than ‘Length’.
Anyway, this approach works for me. It’s simple and easy.
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Wednesday, October 10, 2007 6:26 AM
To: Windows File Systems Devs Interest List
Subject: RE:[ntfsd] Copy UNICODE_STRING to *CHAR
Jan Milan,
What you told me to do works great, though I have a warning about the line:
as_str.MaximumLength = RtlUnicodeStringToAnsiSize(&us_str);
I says that I assign a ULONG to USHORT, and there can be a loss of data.
Anyway, it works!
But now I have another question: After I initialize the pchar_str I send it
to a user mode application and print it there. When I print it there I get
some strange characters. That happens when I send something in hebrew. My
question is: what is the size of each character in pchar_str and how can I
get it in my application without loss of data?
NTFSD 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@msn.com
To unsubscribe send a blank email to xxxxx@lists.osr.com