query related to RtlUnicodeStringToAnsiString()

hi ,

I am using RtlUnicodeStringToAnsiString() to convert a Unicode string to
Ansi string, but the conversion is not working. my Ansi String buffer
contains no data.

The code snippet is given below

UNICODE_STRING tempeunicode;
ANSI_STRING tempansi;
NTSTATUS Status;
ULONG ansilen;
RtlInitUnicodeString(&tempeunicode,L"TEMPDATA");
RtlInitAnsiString(&tempansi,NULL);

ansilen = RtlUnicodeStringToAnsiSize(&tempeunicode);
DbgPrint( “Current IRQL %x \n”,KeGetCurrentIrql());

Status = RtlUnicodeStringToAnsiString(&tempansi,&tempeunicode,TRUE);
if( !NT_SUCCESS( Status ) )
{
DbgPrint( " RtlUnicodeStringToAnsiSize failed \n ");
return Status;
}

DbgPrint( “Current IRQL %x \n”,KeGetCurrentIrql());
RtlFreeAnsiString(&tempansi);
RtlFreeUnicodeString(&tempeunicode);

The data in the unicode string is a value queried from registry. There is
valid data in the unicode string during the call to
RtlUnicodeStringToAnsiString(). The call is getting called at IRQL
PASSIVE_LEVEL. The return status of RtlUnicodeStringToAnsiString() is
STATUS_SUCCESS.

I tried allocating the buffer for the ansi string before the call and
passing FALSE to RtlUnicodeStringToAnsiString(). Then also i observed same
behaviour.

The call to RtlUnicodeStringToAnsiSize() returns the size of the string as
1 .
I would like to know am i missing out something here, or is there some
other way to get this conversion done.

thanks in advance
with regards
San


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Did you cut and paste directly from your code editor, or did you retype
it? It’s hard to tell, and retyping is a good way to silently fix bugs
that are in your actual code.

&*&*%*^&Y^*! Stupid, user hostile, moronic, embecilic Notes! I’ve never
used a program that has so many features that I don’t use, while lacking
really obvious ones that I would. If anyone knows how to coerce the Notes
5 client to indent and prefix reply text, please let me know. I haven’t
found it yet.

There’s no need to init the ANSI string to NULL, and that could possibly
be a part of your problem, though I’ve never tried it, so I’m not sure of
it.

Your primary problem is whatever is causing you to get a length of 1 from
the UNICODE_STRING. That means that the system isn’t parsing the
UNICODE_STRING properly.

Lastly, don’t Free the UNICODE_STRING, you will be trying to free memory
from the string table. That should cause a BSOD.

Phil

Please respond to “NT Developers Interest List”
Sent by: xxxxx@lists.osr.com
To: “NT Developers Interest List”
cc:

Subject: [ntdev] query related to RtlUnicodeStringToAnsiString()

hi ,

I am using RtlUnicodeStringToAnsiString() to convert a Unicode string to
Ansi string, but the conversion is not working. my Ansi String buffer
contains no data.

The code snippet is given below

UNICODE_STRING tempeunicode;
ANSI_STRING tempansi;
NTSTATUS Status;
ULONG ansilen;
RtlInitUnicodeString(&tempeunicode,L"TEMPDATA");
RtlInitAnsiString(&tempansi,NULL);

ansilen = RtlUnicodeStringToAnsiSize(&tempeunicode);
DbgPrint( “Current IRQL %x \n”,KeGetCurrentIrql());

Status = RtlUnicodeStringToAnsiString(&tempansi,&tempeunicode,TRUE);
if( !NT_SUCCESS( Status ) )
{
DbgPrint( " RtlUnicodeStringToAnsiSize failed \n ");
return Status;
}

DbgPrint( “Current IRQL %x \n”,KeGetCurrentIrql());
RtlFreeAnsiString(&tempansi);
RtlFreeUnicodeString(&tempeunicode);

The data in the unicode string is a value queried from registry. There is
valid data in the unicode string during the call to
RtlUnicodeStringToAnsiString(). The call is getting called at IRQL
PASSIVE_LEVEL. The return status of RtlUnicodeStringToAnsiString() is
STATUS_SUCCESS.

I tried allocating the buffer for the ansi string before the call and
passing FALSE to RtlUnicodeStringToAnsiString(). Then also i observed same
behaviour.

The call to RtlUnicodeStringToAnsiSize() returns the size of the string as
1 .
I would like to know am i missing out something here, or is there some
other way to get this conversion done.

thanks in advance
with regards
San


You are currently subscribed to ntdev as: xxxxx@seagate.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Check the contents of the UNICODE_STRING->Buffer - is it a valid pointer
Check the contents of UNICODE_STRING->Length/MaxLength. Are they valid and
properly reflecting the length of the string in BYTES.

Gary G. Little
Broadband Storage, Inc.
xxxxx@broadstor.com
xxxxx@inland.net
(949) 7372731

-----Original Message-----
From: Sanesh [mailto:xxxxx@ctd.hcltech.com]
Sent: Tuesday, December 11, 2001 5:42 PM
To: NT Developers Interest List
Subject: [ntdev] query related to RtlUnicodeStringToAnsiString()

hi ,

I am using RtlUnicodeStringToAnsiString() to convert a Unicode string to
Ansi string, but the conversion is not working. my Ansi String buffer
contains no data.

The code snippet is given below

UNICODE_STRING tempeunicode;
ANSI_STRING tempansi;
NTSTATUS Status;
ULONG ansilen;
RtlInitUnicodeString(&tempeunicode,L"TEMPDATA");
RtlInitAnsiString(&tempansi,NULL);

ansilen = RtlUnicodeStringToAnsiSize(&tempeunicode);
DbgPrint( “Current IRQL %x \n”,KeGetCurrentIrql());

Status = RtlUnicodeStringToAnsiString(&tempansi,&tempeunicode,TRUE);
if( !NT_SUCCESS( Status ) )
{
DbgPrint( " RtlUnicodeStringToAnsiSize failed \n ");
return Status;
}

DbgPrint( “Current IRQL %x \n”,KeGetCurrentIrql());
RtlFreeAnsiString(&tempansi);
RtlFreeUnicodeString(&tempeunicode);

The data in the unicode string is a value queried from registry. There is
valid data in the unicode string during the call to
RtlUnicodeStringToAnsiString(). The call is getting called at IRQL
PASSIVE_LEVEL. The return status of RtlUnicodeStringToAnsiString() is
STATUS_SUCCESS.

I tried allocating the buffer for the ansi string before the call and
passing FALSE to RtlUnicodeStringToAnsiString(). Then also i observed same
behaviour.

The call to RtlUnicodeStringToAnsiSize() returns the size of the string as
1 .
I would like to know am i missing out something here, or is there some
other way to get this conversion done.

thanks in advance
with regards
San


You are currently subscribed to ntdev as: xxxxx@broadstor.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com