Drivers and the C Runtime Library.

Does anyone have some good guidelines to follow when/if using the CRTL from
within a kernel-mode driver? The RtlXXXX() functions are incredibly
primitive in many respects, and it would be so much easier to use some of
the standard CRTL functions, but what are the consequences of doing so?

Specifically I am looking at using sprintf()/wsprintf() to generate
formatted strings, and have not found an equivalent RtlXXXX() function.
Creating formatted Unicode strings is a royal pain in the butt, and it would
appear to be much easier to format it first using sprintf()/wsprintf(), and
then use RtlInitUnicodeString() to create the UNICODE_STRING version.

Any thoughts/suggestions/warnings?

You can use “_snwprintf” in the kernel. Looking at my SOURCES file to see
if it includes any special libes, I see that it does not, so the typical
BUILD process will resolve the symbols during linkage/edit. If you are using
the IDE to build your driver then you will have to include the proper LIB.


Gary G. Little
Have Computer, Will Travel …
909-698-3191
909-551-2105

“David Hoy” wrote in message news:xxxxx@ntdev…
>
> Does anyone have some good guidelines to follow when/if using the CRTL
from
> within a kernel-mode driver? The RtlXXXX() functions are incredibly
> primitive in many respects, and it would be so much easier to use some of
> the standard CRTL functions, but what are the consequences of doing so?
>
> Specifically I am looking at using sprintf()/wsprintf() to generate
> formatted strings, and have not found an equivalent RtlXXXX() function.
> Creating formatted Unicode strings is a royal pain in the butt, and it
would
> appear to be much easier to format it first using sprintf()/wsprintf(),
and
> then use RtlInitUnicodeString() to create the UNICODE_STRING version.
>
> Any thoughts/suggestions/warnings?
>
>
>
>
>

David,

There are a bunch of CRTL type functions declared in
the DDK headers (just not documented). For example,
swprintf is defined in stdio.h. I have been using
several of these without any problems.

Walter Oney’s book “Programming the Microsoft Windows
Driver Model” has a nice table of functions that can
be used on page 113 (my edition).

Here’s a quick list:
wcslen
wcscat
wcsncat
wcscpy
wcsncpy
_wcsrev
wcscmp
wcsncmp
_wcsicmp
_wcsnicmp
_wcsnset
wcschr
wcsrchr
wcsspn
wcsstr
_wcslwr
_wcsupr
towlower
towupper
swprintf
_snwprintf
_itow

Randy Cook
Lucid Systems Inc.

— David Hoy wrote:
> Does anyone have some good guidelines to follow
> when/if using the CRTL from
> within a kernel-mode driver? The RtlXXXX()
> functions are incredibly
> primitive in many respects, and it would be so much
> easier to use some of
> the standard CRTL functions, but what are the
> consequences of doing so?
>
> Specifically I am looking at using
> sprintf()/wsprintf() to generate
> formatted strings, and have not found an equivalent
> RtlXXXX() function.
> Creating formatted Unicode strings is a royal pain
> in the butt, and it would
> appear to be much easier to format it first using
> sprintf()/wsprintf(), and
> then use RtlInitUnicodeString() to create the
> UNICODE_STRING version.
>
> Any thoughts/suggestions/warnings?
>
>
>
>
> —
> You are currently subscribed to ntdev as:
> xxxxx@yahoo.com
> To unsubscribe send a blank email to
%%email.unsub%%

__________________________________________________
Do you Yahoo!?
Yahoo! Web Hosting - Let the expert host your site
http://webhosting.yahoo.com

The new Windows DDK (2600.1106) also contains the new header
ntstrsafe.h, which contains Rtl wrapper functions for many of these
calls. For example, RtlStringCchPrintfW would be similar to wsprintf.
Unlike the direct C runtime calls, whose use in kernel mode is
undocumented, ntstrsafe.h is officially mentioned in the release notes,
so you may want to keep that in mind.

David Hoy wrote:

Does anyone have some good guidelines to follow when/if using the CRTL from
within a kernel-mode driver? The RtlXXXX() functions are incredibly
primitive in many respects, and it would be so much easier to use some of
the standard CRTL functions, but what are the consequences of doing so?

Specifically I am looking at using sprintf()/wsprintf() to generate
formatted strings, and have not found an equivalent RtlXXXX() function.
Creating formatted Unicode strings is a royal pain in the butt, and it would
appear to be much easier to format it first using sprintf()/wsprintf(), and
then use RtlInitUnicodeString() to create the UNICODE_STRING version.

Any thoughts/suggestions/warnings?


You are currently subscribed to ntdev as: xxxxx@stg.com
To unsubscribe send a blank email to %%email.unsub%%

David Hoy wrote:

Does anyone have some good guidelines to follow when/if using the CRTL from
within a kernel-mode driver? The RtlXXXX() functions are incredibly
primitive in many respects, and it would be so much easier to use some of
the standard CRTL functions, but what are the consequences of doing so?

Specifically I am looking at using sprintf()/wsprintf() to generate
formatted strings, and have not found an equivalent RtlXXXX() function.
Creating formatted Unicode strings is a royal pain in the butt, and it would
appear to be much easier to format it first using sprintf()/wsprintf(), and
then use RtlInitUnicodeString() to create the UNICODE_STRING version.

Microsoft is now discouraging use of null-terminated strings in the
kernel because of their potential for errors. The NtStrsafe.h set of
functions in the .net DDK is now preferred.

You should never use wsprintf anyway, because it can easily overwrite a
buffer. _snwprintf is better but still on the “mildly deprecated” list
because it won’t put a null terminator on the target string if the
needed length is >= the length of the target buffer.


Walter Oney, Consulting and Training
Basic and Advanced Driver Programming Seminars
Now teaming with John Hyde for USB Device Engineering Seminars
Check out our schedule at http://www.oneysoft.com