Is there a way to convert PCHAR to PWCHAR I searched a lot but found
nothing.
–
- amitr0
Is there a way to convert PCHAR to PWCHAR I searched a lot but found
nothing.
–
Sheesh, you certainly did not spend long looking. You can always use the
ANSI to UNICODE functions, but if converting your string to a counted
string is a pain in the butt then writing you own ain’t that big a deal.
Gary G. Little
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@gmail.com
Sent: Tuesday, April 18, 2006 11:19 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] converting PCHAR to PWCHAR
Is there a way to convert PCHAR to PWCHAR I searched a lot but found
nothing.
–
nah, I dont want such a diverse solution, as to convert it to ansi then to
unicode…anything simpler would be better.
You can use UniToBCS and BCSToUni.
This works fine for Win98 atleast.
Regards,
Shreshth
On 4/18/06, amitr0 wrote:
>
> Is there a way to convert PCHAR to PWCHAR I searched a lot but found
> nothing.
>
> –
>
> - amitr0 — Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256 To unsubscribe, visit the List
> Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
If you think that’s “complicated”, then you shouldn’t be in kernel land.
ANSI / UNICODE conversion is simple. Annoying sometimes, but it’s simple.
Read the DDK docs, search the archives. This is a basic, basic issue, and
you can’t simply cast PWCHAR to PCHAR.
– arlie
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of amitr0
Sent: Tuesday, April 18, 2006 12:39 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] converting PCHAR to PWCHAR
nah, I dont want such a diverse solution, as to convert it to ansi then to
unicode…anything simpler would be better. — Questions? First check the
Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256 To
unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
amitr0 wrote:
Is there a way to convert PCHAR to PWCHAR I searched a lot but found
nothing.
I find that hard to imagine.
Are you asking about kernel mode or user mode? Actually, it doesn’t
much matter. The “mbstowcs()” call in the C run-time library will do
this conversion, and it is present in libcntpr.lib for kernel drivers.
Note that this conversion cannot be done at a raised IRQL.
What are you actually trying to do? It is somewhat unusual to end up
with ANSI chars in a kernel driver.
–
Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.
yeah, actually I used the wrong word, your’s is closer, “ANNOYING” and I
wanted to avoid anywany function calls as possible and by the “quicker way”
I meant avoiding these calls and probably zeroing to ONE CALL.
amitr0 wrote:
nah, I dont want such a diverse solution, as to convert it to ansi
then to unicode…anything simpler would be better.
Then I’m not sure you know what you are talking about. CHARs are ANSI,
and WCHARs are Unicode. To convert a CHAR to a WCHAR, you have to
convert ANSI to Unicode.
If you are guaranteed that the characters are all in the lowest 128
characters of ASCII (such as an IP address or a hexadecimal string),
then you can do the “conversion” just by copying each char to a
wchar_t. However, don’t come complaining to us when your driver messes
up the words “cañon” or “rèsumé”.
–
Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.
You could just cast the pointer? Hahahahahahahahahahahahaha ![]()
“amitr0” wrote in message news:xxxxx@ntdev…
Is there a way to convert PCHAR to PWCHAR I searched a lot but found
nothing.
–
- amitr0
Tim,
Thanks for the tip on
mbstowcs()
that is what I needed, I was not sure whether is it safe to use this API in
Kernel mode.
Regards,
Amitr0
Well he could build a pair of classes, one for char and one for wchar
and then have a cast operator that converted from one to the other. I’m
thinking for sure that is the best way to go.
p.s. can we please stop torturing the nubie now?
p.p.s. by ‘now’ I mean, not that I’ve had my fun.
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Lyndon J. Clarke
Sent: Tuesday, April 18, 2006 1:27 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] converting PCHAR to PWCHAR
You could just cast the pointer? Hahahahahahahahahahahahaha ![]()
“amitr0” wrote in message news:xxxxx@ntdev…
Is there a way to convert PCHAR to PWCHAR I searched a lot but found
nothing.
–
- amitr0
—
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
Technically, no it is NOT safe to use mbstowcs in the kernel. You should
be using safe string ops and some form of RtlStringCchVPrintf should
safely convert your CHAR to a WCHAR. If you use mbstowcs then you best
make sure the buffer will not overrun.
And again, this is covered in t he online documentation.
Gary G. Little
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@gmail.com
Sent: Tuesday, April 18, 2006 12:47 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] converting PCHAR to PWCHAR
Tim,
Thanks for the tip on
mbstowcs()
that is what I needed, I was not sure whether is it safe to use this API
in Kernel mode.
Regards,
Amitr0
— Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256 To unsubscribe, visit the List
Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
Or, if you want to take the “annoying” route:
PCHAR stringPointer = “USA”;
ANSI_STRING ansiString;
UNICODE_STRING unicodeString;
NTSTATUS status;
RtlInitAnsiString(&ansiString, stringPointer);
status = RtlAnsiStringToUnicodeString(&unicodeString,
&ansiString, TRUE);
if (NT_SUCCESS(status))
{
RtlFreeUnicodeString(&unicodeString);
}
Wait - how is that annoying? It seems pretty simple to me.
-p
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@seagate.com
Sent: Tuesday, April 18, 2006 11:11 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] converting PCHAR to PWCHAR
Technically, no it is NOT safe to use mbstowcs in the kernel. You should
be using safe string ops and some form of RtlStringCchVPrintf should
safely convert your CHAR to a WCHAR. If you use mbstowcs then you best
make sure the buffer will not overrun.
And again, this is covered in t he online documentation.
Gary G. Little
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@gmail.com
Sent: Tuesday, April 18, 2006 12:47 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] converting PCHAR to PWCHAR
Tim,
Thanks for the tip on
mbstowcs()
that is what I needed, I was not sure whether is it safe to use this API
in Kernel mode.
Regards,
Amitr0
— Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256 To unsubscribe, visit the
List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
—
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
amitr0 wrote:
Tim,
Thanks for the tip on
mbstowcs()
that is what I needed, I was not sure whether is it safe to use this
API in Kernel mode.
Yes, I said it was. It is present in libcntpr.lib, which provides a
relatively complete C run-time specifically for kernel drivers.
Again, however, you cannot call this at a raised IRQL. The Unicode
conversion tables are all in paged memory.
–
Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.
It’s not bad for a single string, but if you try to write something like a bus driver (with all of the freaking query this and that) it becomes maddening.
None of this is complex, but the code gets really ugly really fast, and it is just a royal pain in the posterior.
Mark provided the only reasonable solution. Just wring out a couple of good classes and never have to worry about a string conversion in the kernel again ![]()
Bill M.
“Peter Wieland” wrote in message news:xxxxx@ntdev…
Or, if you want to take the “annoying” route:
PCHAR stringPointer = “USA”;
ANSI_STRING ansiString;
UNICODE_STRING unicodeString;
NTSTATUS status;
RtlInitAnsiString(&ansiString, stringPointer);
status = RtlAnsiStringToUnicodeString(&unicodeString, &ansiString, TRUE);
if (NT_SUCCESS(status))
{
RtlFreeUnicodeString(&unicodeString);
}
Wait - how is that annoying? It seems pretty simple to me.
-p
------------------------------------------------------------------------------
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@seagate.com
Sent: Tuesday, April 18, 2006 11:11 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] converting PCHAR to PWCHAR
Technically, no it is NOT safe to use mbstowcs in the kernel. You should be using safe string ops and some form of RtlStringCchVPrintf should safely convert your CHAR to a WCHAR. If you use mbstowcs then you best make sure the buffer will not overrun.
And again, this is covered in t he online documentation.
Gary G. Little
------------------------------------------------------------------------------
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Tuesday, April 18, 2006 12:47 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] converting PCHAR to PWCHAR
Tim,
Thanks for the tip on
mbstowcs()
that is what I needed, I was not sure whether is it safe to use this API in Kernel mode.
Regards,
Amitr0
— Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256 To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
—
Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256
To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
Peter Wieland wrote:
Or, if you want to take the “annoying” route:
PCHAR stringPointer = “USA”;
ANSI_STRING ansiString;
UNICODE_STRING unicodeString;
NTSTATUS status;RtlInitAnsiString(&ansiString, stringPointer);
status = RtlAnsiStringToUnicodeString(&unicodeString,
&ansiString, TRUE);if (NT_SUCCESS(status))
{
> RtlFreeUnicodeString(&unicodeString);
> }
>
>
> Wait - how is that annoying? It seems pretty simple to me.
>
> -p
>
Here’s a little improvement:
PCHAR StringPointer = “USA”;
UNICODE_STRING UnicodeString;
NTSTATUS Status;
Status = RtlCreateUnicodeStringFromAsciiz(&UnicodeString,
StringPointer);
if (NT_SUCCESS(Status))
{
RtlFreeUnicodeString(&UnicodeString);
}
Is RtlCreateUnicodeStringFromAsciiz doc’ed in the WDK? It certainly is
not doc’ed in the currently released DDK.
d
– I can spell, I just can’t type.
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Alex Ionescu
[397670]
Sent: Thursday, April 27, 2006 10:54 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] converting PCHAR to PWCHAR
Peter Wieland wrote:
Or, if you want to take the “annoying” route:
PCHAR stringPointer = “USA”;
ANSI_STRING ansiString;
UNICODE_STRING unicodeString;
NTSTATUS status;RtlInitAnsiString(&ansiString, stringPointer);
status = RtlAnsiStringToUnicodeString(&unicodeString,
&ansiString, TRUE);if (NT_SUCCESS(status))
{
> RtlFreeUnicodeString(&unicodeString);
> }
>
>
> Wait - how is that annoying? It seems pretty simple to me.
>
> -p
>
Here’s a little improvement:
PCHAR StringPointer = “USA”;
UNICODE_STRING UnicodeString;
NTSTATUS Status;
Status = RtlCreateUnicodeStringFromAsciiz(&UnicodeString,
StringPointer);
if (NT_SUCCESS(Status))
{
RtlFreeUnicodeString(&UnicodeString);
}
—
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
5365 nope
“Doron Holan” wrote in message
news:xxxxx@ntdev…
Is RtlCreateUnicodeStringFromAsciiz doc’ed in the WDK? It certainly is
not doc’ed in the currently released DDK.
d
– I can spell, I just can’t type.
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Alex Ionescu
[397670]
Sent: Thursday, April 27, 2006 10:54 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] converting PCHAR to PWCHAR
Peter Wieland wrote:
> Or, if you want to take the “annoying” route:
>
>
> PCHAR stringPointer = “USA”;
> ANSI_STRING ansiString;
> UNICODE_STRING unicodeString;
> NTSTATUS status;
>
> RtlInitAnsiString(&ansiString, stringPointer);
> status = RtlAnsiStringToUnicodeString(&unicodeString,
> &ansiString, TRUE);
>
> if (NT_SUCCESS(status))
> {
>
> RtlFreeUnicodeString(&unicodeString);
> }
>
>
> Wait - how is that annoying? It seems pretty simple to me.
>
> -p
>
Here’s a little improvement:
PCHAR StringPointer = “USA”;
UNICODE_STRING UnicodeString;
NTSTATUS Status;
Status = RtlCreateUnicodeStringFromAsciiz(&UnicodeString,
StringPointer);
if (NT_SUCCESS(Status))
{
RtlFreeUnicodeString(&UnicodeString);
}
—
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
Doron Holan wrote:
Is RtlCreateUnicodeStringFromAsciiz doc’ed in the WDK? It certainly is
not doc’ed in the currently released DDK.d
– I can spell, I just can’t type.
Oops, I didn’t bother to check; I’ve been using it on my personal tools
for ages.
Apologies then, this is undocumented and shouldn’t be used in a
production driver. (Although all it does is exactly create an ANSI
string internally… but oh well, there must be a reason why it’s not
documented).
Best regards,
Alex Ionescu
Didn’t think so. I can’t recommend to folks to use a function that
undocumented where the documented function is just as easy to use.
d
– I can spell, I just can’t type.
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Lyndon J. Clarke
Sent: Thursday, April 27, 2006 3:14 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] converting PCHAR to PWCHAR
5365 nope
“Doron Holan” wrote in message
news:xxxxx@ntdev…
Is RtlCreateUnicodeStringFromAsciiz doc’ed in the WDK? It certainly is
not doc’ed in the currently released DDK.
d
– I can spell, I just can’t type.
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Alex Ionescu
[397670]
Sent: Thursday, April 27, 2006 10:54 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] converting PCHAR to PWCHAR
Peter Wieland wrote:
> Or, if you want to take the “annoying” route:
>
>
> PCHAR stringPointer = “USA”;
> ANSI_STRING ansiString;
> UNICODE_STRING unicodeString;
> NTSTATUS status;
>
> RtlInitAnsiString(&ansiString, stringPointer);
> status = RtlAnsiStringToUnicodeString(&unicodeString,
> &ansiString, TRUE);
>
> if (NT_SUCCESS(status))
> {
>
> RtlFreeUnicodeString(&unicodeString);
> }
>
>
> Wait - how is that annoying? It seems pretty simple to me.
>
> -p
>
Here’s a little improvement:
PCHAR StringPointer = “USA”;
UNICODE_STRING UnicodeString;
NTSTATUS Status;
Status = RtlCreateUnicodeStringFromAsciiz(&UnicodeString,
StringPointer);
if (NT_SUCCESS(Status))
{
RtlFreeUnicodeString(&UnicodeString);
}
—
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
—
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer