Converting unicode strings to other formats

Hi,
I want to convert a unicode string to utf8 and vice versa in my driver.
Whats the best way to do this?
Is there any equivalent of WideCharToMultiByte and its converse function
for Windows drivers? I see EngWideCharToMultiByte in the DDK but including
<winddi.h> generates a whole bunch of compile errors and even if I just declare this
function Im not sure which library needs to be linked in to be able to use
this.

Im assuming that WideCharToMultiByte() cannot be used directly in a driver
being a Win32 function thats implemented in kernel32.lib (it fails to
compile once again as windows.h needs to be included). Is that a correct
assumption? Is there any list of user level libraries that can be used in
drivers?

Thanks,
Jagannath</winddi.h>

What is wrong with RtlUnicodeStringToAnsiString()? Search of DDK for
“Unicode ANSI convert” finds 27 topics.

“Jagannath Krishnan” wrote in message
news:xxxxx@ntdev…
>
> Hi,
> I want to convert a unicode string to utf8 and vice versa in my driver.
> Whats the best way to do this?
> Is there any equivalent of WideCharToMultiByte and its converse function
> for Windows drivers? I see EngWideCharToMultiByte in the DDK but including
> <winddi.h> generates a whole bunch of compile errors and even if I just
declare this
> function Im not sure which library needs to be linked in to be able to use
> this.
>
> Im assuming that WideCharToMultiByte() cannot be used directly in a driver
> being a Win32 function thats implemented in kernel32.lib (it fails to
> compile once again as windows.h needs to be included). Is that a correct
> assumption? Is there any list of user level libraries that can be used in
> drivers?
>
> Thanks,
> Jagannath
>
></winddi.h>

Read the OP. He doesn’t want to use the ANSI code page in his
conversion, he wants UTF8 (though I sheepishly admit I don’t know the
difference :-).

I have to ask the OP, though: why do you want to convert a unicode
string into something other than ANSI from inside a device driver?
Everything in kernel-land (pretty much) uses Unicode, and anything in
user-land should probably be done in a user mode helper program.

David J. Craig wrote:

What is wrong with RtlUnicodeStringToAnsiString()? Search of DDK for
“Unicode ANSI convert” finds 27 topics.

“Jagannath Krishnan” wrote in message
> news:xxxxx@ntdev…
>
>>Hi,
>>I want to convert a unicode string to utf8 and vice versa in my driver.
>>Whats the best way to do this?
>>Is there any equivalent of WideCharToMultiByte and its converse function
>>for Windows drivers? I see EngWideCharToMultiByte in the DDK but including
>><winddi.h> generates a whole bunch of compile errors and even if I just
>
> declare this
>
>>function Im not sure which library needs to be linked in to be able to use
>>this.
>>
>>Im assuming that WideCharToMultiByte() cannot be used directly in a driver
>>being a Win32 function thats implemented in kernel32.lib (it fails to
>>compile once again as windows.h needs to be included). Is that a correct
>>assumption? Is there any list of user level libraries that can be used in
>>drivers?
>>
>>Thanks,
>>Jagannath
>>
>>
>
>
>
>
>


…/ray..</winddi.h>

I didnt think you could convert a unicode string to utf8 using that
function. The functions I mentioned (EngWideCharToMultiByte and
WideCharToMultiByte) allow the specification of an arbitrary code page
(which could be utf8 or ansi or something else).

Any ideas on how I can convert to utf8 in the driver?

Thanks,
Jagannath

Ray,
I need to do this to be able to pass strings from my driver through a
transport to a Linux machine. Utf8 is just a unicode encoding scheme that
will preserve the integrity of the string across different locales.

Id prefer to do this in the driver if possible.

Thanks,
Jagannath

Haven’t found any DDIs for this, but there’s sample code for how to do
this conversion at: ftp://www.unicode.org/Public/PROGRAMS/CVTUTF/

Jagannath Krishnan wrote:

Ray,
I need to do this to be able to pass strings from my driver through a
transport to a Linux machine. Utf8 is just a unicode encoding scheme that
will preserve the integrity of the string across different locales.

Id prefer to do this in the driver if possible.

Thanks,
Jagannath


…/ray..

Thanks Ray,

Id like to do this using some standard API if possible instead of
implementing a conversion routine myself like the samples you sent a
pointer to. This is because XP differs slightly from earlier NT OSes in
the encoding it uses for Unicode string (utf16 as opposed to ucs2).

EngWideCharToMultiByte() which is documented in the ddk seems to do
exactly what I want. Any idea which library I need to link against to be
able to use this function?

Ofcourse, if theres some other API I can use that’d be great too.
Jagannath

Jagannath,

Would it be possible for you to send the string as-is and do the
conversion on the Linux end?

I’m curious about your statement “XP differs slightly from earlier NT
OSes in the encoding it uses for Unicode string (utf16 as opposed to
ucs2)”. What is the difference? Does this mean if I write a unicode
string into a file on Win2000, it will read back differently on XP, and
vice versa? Surely they wouldn’t change the representation… would
they? Thousands of programs have unicode strings compiled into them.

Chuck

----- Original Message -----
From: “Jagannath Krishnan”
To: “Windows System Software Devs Interest List”
Sent: Saturday, September 13, 2003 7:07 AM
Subject: [ntdev] Re: Converting unicode strings to other formats

> Thanks Ray,
>
> Id like to do this using some standard API if possible instead of
> implementing a conversion routine myself like the samples you sent a
> pointer to. This is because XP differs slightly from earlier NT OSes
in
> the encoding it uses for Unicode string (utf16 as opposed to ucs2).
>
> EngWideCharToMultiByte() which is documented in the ddk seems to do
> exactly what I want. Any idea which library I need to link against to
be
> able to use this function?
>
> Ofcourse, if theres some other API I can use that’d be great too.
> Jagannath
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@cbatson.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>

Folks,

The code to convert UTF-16 to UTF-8 is small and it never changes. It’s
perfectly reasonable to add it to your driver. As previously referenced, you
can get it from unicode.org.

> Is there any equivalent of WideCharToMultiByte and its converse function

for Windows drivers?

RtlUnicodeStringToAnsiString

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

That’s ACP-only, is it not?

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Maxim S. Shatskih
Sent: Sunday, September 14, 2003 9:18 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Re: Converting unicode strings to other formats

Is there any equivalent of WideCharToMultiByte and its converse
function for Windows drivers?

RtlUnicodeStringToAnsiString

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@dchbk.us
To unsubscribe send a blank email to xxxxx@lists.osr.com