Redigera

Dela via


Importing Kernel-Mode Safe String Functions

Starting with Windows XP, the kernel-mode safe string library is available as a collection of inline functions that are defined in the Ntstrsafe.h header file.

To use the kernel-mode safe string functions

Include the header file, as shown.

#include <ntstrsafe.h>

You can make available only the byte-counted or only the character-counted safe string functions.

To allow only byte-counted functions

Include the following line in your code before including the Ntstrsafe.h header file.

#define NTSTRSAFE_NO_CCH_FUNCTIONS

To allow only character-counted functions

Include the following line in your code before including the Ntstrsafe.h header file.

#define NTSTRSAFE_NO_CB_FUNCTIONS

You can define either NTSTRSAFE_NO_CB_FUNCTIONS or NTSTRSAFE_NO_CCH_FUNCTIONS, but not both.

You can make the UNICODE_STRING structure functions unavailable.

To make UNICODE_STRING structure functions unavailable

Include the following line in your code before including the Ntstrsafe.h header file.

#define NTSTRSAFE_NO_UNICODE_STRING_FUNCTIONS

The maximum number of characters that any ANSI or Unicode string can contain is NTSTRSAFE_MAX_CCH. The maximum number of characters that a UNICODE_STRING structure can contain is NTSTRSAFE_UNICODE_STRING_MAX_CCH. These constants are defined in Ntstrsafe.h.

Your driver can assign smaller values to NTSTRSAFE_MAX_CCH and NTSTRSAFE_UNICODE_STRING_MAX_CCH by including the following lines in your code before including Ntstrsafe.h.

#define NTSTRSAFE_MAX_CCH  <new-value>
#define NTSTRSAFE_UNICODE_STRING_MAX_CCH  <new-value>

Directives in Ntstrsafe.h verify that your new values are not larger than the default values.