RtlUnicodeStringToAnsiString

hi all,

does RtlUnicodeStringToAnsiString work …
i have tried it several times and with both the TRUE
and the FALSE arguments ( for destination string
allocation ) but it not only fails but gives me a page
fault … due to this the machine immediately reboots.
:frowning:

the code is like this
ANSI_STRING FileNameAnsi;
UNICODE_STRING FileNameUnicode;

RtlUnicodeStringToAnsiString( &FileNameAnsi ,
&FileNameUnicode , TRUE ) ; // this didnt work

and

RtlUnicodeStringToAnsiString( &FileNameAnsi ,
&FileNameUnicode , FALSE ) ; // this didnt work too

please gimme some ideas on this…

– Thank you so much
– Harshal


Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35
a year! http://personal.mail.yahoo.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

  1. You must be running at IRQL PASSIVE_LEVEL.
  2. Your ‘FileNameUnicode’ string must be defined
    somewhere - otherwise, ‘RtlUnicodeString’ doesn’t have a clue
    of how big is the buffer space you want to allocate, if you
    specify a TRUE argument… :wink:

Miguel Monteiro
xxxxx@criticalsoftware.com
www.criticalsoftware.com

«Humour and love are God’s answers
to Human weaknesses»

On Thursday, June 07, 2001 12:36 PM “cts mad (a.k.a. Harshal)” wrote:

hi all,

does RtlUnicodeStringToAnsiString work …
i have tried it several times and with both the TRUE
and the FALSE arguments ( for destination string
allocation ) but it not only fails but gives me a page
fault … due to this the machine immediately reboots.

the code is like this
ANSI_STRING FileNameAnsi;
UNICODE_STRING FileNameUnicode;

RtlUnicodeStringToAnsiString( &FileNameAnsi ,
&FileNameUnicode , TRUE ) ; // this didnt work

and

RtlUnicodeStringToAnsiString( &FileNameAnsi ,
&FileNameUnicode , FALSE ) ; // this didnt work too

please gimme some ideas on this…

– Thank you so much
– Harshal


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

i tried out every possible combination of calling the
function but it still didnt work

can somebody please send me a code which successfully
converts a unicode string to a ansi string without a
crash!!!

–thank you so much
– harshal

— Miguel Monteiro
wrote:
> 1. You must be running at IRQL PASSIVE_LEVEL.
> 2. Your ‘FileNameUnicode’ string must be defined
> somewhere - otherwise, ‘RtlUnicodeString’ doesn’t
> have a clue
> of how big is the buffer space you want to allocate,
> if you
> specify a TRUE argument… :wink:
>
> Miguel Monteiro
> xxxxx@criticalsoftware.com
> www.criticalsoftware.com
>
------------------------------------------------------------
> «Humour and love are God’s answers
> to Human weaknesses»
>
------------------------------------------------------------
>
> On Thursday, June 07, 2001 12:36 PM “cts mad (a.k.a.
> Harshal)” wrote:
>
>
> hi all,
>
> does RtlUnicodeStringToAnsiString work …
> i have tried it several times and with both the
> TRUE
> and the FALSE arguments ( for destination string
> allocation ) but it not only fails but gives me a
> page
> fault … due to this the machine immediately
> reboots.
>
>
>
> the code is like this
> ANSI_STRING FileNameAnsi;
> UNICODE_STRING FileNameUnicode;
>
> RtlUnicodeStringToAnsiString( &FileNameAnsi ,
> &FileNameUnicode , TRUE ) ; // this didnt work
>
> and
>
> RtlUnicodeStringToAnsiString( &FileNameAnsi ,
> &FileNameUnicode , FALSE ) ; // this didnt work too
>
> please gimme some ideas on this…
>
> – Thank you so much
> – Harshal
>
>
>
> —
> You are currently subscribed to ntdev as:
> xxxxx@yahoo.com
> To unsubscribe send a blank email to
leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35
a year! http://personal.mail.yahoo.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

Here is how I used and it works for me:

{
char PtrFullPathFname[MAX_PATH];
POBJECT_NAME_INFORMATION nameInfo=NULL;
ANSI_STRING strVname;

…get the path name info as unicode string in nameInfo,

if(STATUS_SUCCESS ==
RtlUnicodeStringToAnsiString(&strVname,&FnameInfor->Name,TRUE))
{
strcpy(PtrFullPathFname,strVname.Buffer);
RtlFreeAnsiString(&strVname);
}

}

You can find some of this from MS sample code as sfilter driver.

Good luck,
Lixin

----- Original Message -----
From: “Miguel Monteiro”
To: “NT Developers Interest List”
Sent: Thursday, June 07, 2001 7:50 AM
Subject: [ntdev] Re: RtlUnicodeStringToAnsiString

> 1. You must be running at IRQL PASSIVE_LEVEL.
> 2. Your ‘FileNameUnicode’ string must be defined
> somewhere - otherwise, ‘RtlUnicodeString’ doesn’t have a clue
> of how big is the buffer space you want to allocate, if you
> specify a TRUE argument… :wink:
>
> Miguel Monteiro
> xxxxx@criticalsoftware.com
> www.criticalsoftware.com
> ------------------------------------------------------------
> «Humour and love are God’s answers
> to Human weaknesses»
> ------------------------------------------------------------
>
> On Thursday, June 07, 2001 12:36 PM “cts mad (a.k.a. Harshal)” wrote:
>
>
> hi all,
>
> does RtlUnicodeStringToAnsiString work …
> i have tried it several times and with both the TRUE
> and the FALSE arguments ( for destination string
> allocation ) but it not only fails but gives me a page
> fault … due to this the machine immediately reboots.
>
>
>
> the code is like this
> ANSI_STRING FileNameAnsi;
> UNICODE_STRING FileNameUnicode;
>
> RtlUnicodeStringToAnsiString( &FileNameAnsi ,
> &FileNameUnicode , TRUE ) ; // this didnt work
>
> and
>
> RtlUnicodeStringToAnsiString( &FileNameAnsi ,
> &FileNameUnicode , FALSE ) ; // this didnt work too
>
> please gimme some ideas on this…
>
> – Thank you so much
> – Harshal
>
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@indefense.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

What is the IRQL? Functions such as this are for PASSIVE_LEVEL.

Gary G. Little
Staff Engineer
Broadband Storage, Inc.
xxxxx@Broadstor.com
xxxxx@inland.net

-----Original Message-----
From: cts mad [mailto:xxxxx@yahoo.com]
Sent: Thursday, June 07, 2001 4:36 AM
To: NT Developers Interest List
Subject: [ntdev] RtlUnicodeStringToAnsiString

hi all,

does RtlUnicodeStringToAnsiString work …
i have tried it several times and with both the TRUE
and the FALSE arguments ( for destination string
allocation ) but it not only fails but gives me a page
fault … due to this the machine immediately reboots.
:frowning:

the code is like this
ANSI_STRING FileNameAnsi;
UNICODE_STRING FileNameUnicode;

RtlUnicodeStringToAnsiString( &FileNameAnsi ,
&FileNameUnicode , TRUE ) ; // this didnt work

and

RtlUnicodeStringToAnsiString( &FileNameAnsi ,
&FileNameUnicode , FALSE ) ; // this didnt work too

please gimme some ideas on this…

– Thank you so much
– Harshal


Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35
a year! http://personal.mail.yahoo.com/


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

Hello,

I think I know your problem. I have faced this problem
before.

Basically the DDK documentation of DestinationString
parameter in RtlUnicodeStringToAnsiString is
confusing.

The DDK documentation says

"DestinationString
Points to a caller-allocated buffer for the ANSI
string or is NULL if AllocateDestinationString is set
to TRUE. If the translation cannot be done because a
character in the Unicode string does not map to an
ANSI character in the current system locale, an error
is returned. "

From the documentation it looks like if
AllocateDestinationString is TRUE, you can pass NULL
for this parameter. However you need to pass valid
PANSI_STRING parameter to this with Buffer member set
to NULL.

So, in your case,

If you set AllocateDestinationString to TRUE, make
sure that you do memset(&FileNameAnsi, 0,
sizeof(FileNameAnsi)) before that.

If you set AllocateDestinationString to FALSE, make
sure that you allocate sufficient size buffer to hold
ansi string content and intialize FileNameAnsi
accordingly

Hope this helps.
-Prasad

-----Original Message-----
From: cts mad [mailto:xxxxx@yahoo.com]
Sent: Thursday, June 07, 2001 4:36 AM
To: NT Developers Interest List
Subject: [ntdev] RtlUnicodeStringToAnsiString

hi all,

does RtlUnicodeStringToAnsiString work …
i have tried it several times and with both the
TRUE
and the FALSE arguments ( for destination string
allocation ) but it not only fails but gives me a
page
fault … due to this the machine immediately
reboots.
:frowning:

the code is like this
ANSI_STRING FileNameAnsi;
UNICODE_STRING FileNameUnicode;

RtlUnicodeStringToAnsiString( &FileNameAnsi ,
&FileNameUnicode , TRUE ) ; // this didnt work

and

RtlUnicodeStringToAnsiString( &FileNameAnsi ,
&FileNameUnicode , FALSE ) ; // this didnt work too

please gimme some ideas on this…

– Thank you so much
– Harshal


Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail -
only $35
a year! http://personal.mail.yahoo.com/


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:
xxxxx@yahoo.com
To unsubscribe send a blank email to
leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

=====
Prasad S. Dabak
Chief Software Architect
Ensim India Private Limited
http://www.ensim.com
Co-author of the book “Undocumented Windows NT”
ISBN 0764545698


Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35
a year! http://personal.mail.yahoo.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

Hello,

Here is the sample code…

UNICODE_STRING uFileName;
ANSI_STRING aFileName;
NTSTATUS rc;

RtlInitUnicodeString(&uFileName,
L"\Device\HardDisk0");
memset(&aFileName, 0, sizeof(aFileName));

rc=RtlUnicodeStringToAnsiString(&aFileName,
&uFileName,
TRUE);
if (rc==STATUS_SUCCESS) {
DbgPrint(“aFileName=%s\n”, aFileName.Buffer);
RtlFreeAnsiString(&aFileName);
}

-Prasad

— cts mad wrote:
>
> i tried out every possible combination of calling
> the
> function but it still didnt work
>
> can somebody please send me a code which
> successfully
> converts a unicode string to a ansi string without a
> crash!!!
>
> --thank you so much
> – harshal
>
> — Miguel Monteiro
> wrote:
> > 1. You must be running at IRQL PASSIVE_LEVEL.
> > 2. Your ‘FileNameUnicode’ string must be defined
> > somewhere - otherwise, ‘RtlUnicodeString’ doesn’t
> > have a clue
> > of how big is the buffer space you want to
> allocate,
> > if you
> > specify a TRUE argument… :wink:
> >
> > Miguel Monteiro
> > xxxxx@criticalsoftware.com
> > www.criticalsoftware.com
> >
>
------------------------------------------------------------
> > «Humour and love are God’s answers
> > to Human weaknesses»
> >
>
------------------------------------------------------------
> >
> > On Thursday, June 07, 2001 12:36 PM “cts mad
> (a.k.a.
> > Harshal)” wrote:
> >
> >
> > hi all,
> >
> > does RtlUnicodeStringToAnsiString work …
> > i have tried it several times and with both the
> > TRUE
> > and the FALSE arguments ( for destination string
> > allocation ) but it not only fails but gives me a
> > page
> > fault … due to this the machine immediately
> > reboots.
> >
> >
> >
> > the code is like this
> > ANSI_STRING FileNameAnsi;
> > UNICODE_STRING FileNameUnicode;
> >
> > RtlUnicodeStringToAnsiString( &FileNameAnsi ,
> > &FileNameUnicode , TRUE ) ; // this didnt work
> >
> > and
> >
> > RtlUnicodeStringToAnsiString( &FileNameAnsi ,
> > &FileNameUnicode , FALSE ) ; // this didnt work
> too
> >
> > please gimme some ideas on this…
> >
> > – Thank you so much
> > – Harshal
> >
> >
> >
> > —
> > You are currently subscribed to ntdev as:
> > xxxxx@yahoo.com
> > To unsubscribe send a blank email to
> leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
>
>
>
> Do You Yahoo!?
> Get personalized email addresses from Yahoo! Mail -
> only $35
> a year! http://personal.mail.yahoo.com/
>
> —
> You are currently subscribed to ntdev as:
> xxxxx@yahoo.com
> To unsubscribe send a blank email to
leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

=====
Prasad S. Dabak
Chief Software Architect
Ensim India Private Limited
http://www.ensim.com
Co-author of the book “Undocumented Windows NT”
ISBN 0764545698


Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35
a year! http://personal.mail.yahoo.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