"Daniel" <> wrote in message
news

948E245-FBAA-4503-AF65-...
>
> When my driver is verified by the driver verifir on Win7 (64 bit),
> NdisOpenConfigurationKeyByIndex returns KeyName not NULL terminated.
>
> The system crashes when the driver tries to access the buffer.
> For example it crashes by printing the buffer.
> Why this functions does not return a good unicode string?
This is a design decision from days of yore.
Strings used in NT kernel stuff are counted. Expecting them to be null
terminated is a bug.
> How can I NULL terminate the returned Unicode string?
You don't. Just work with counted strings, like everyone else does.
> CODE:
> NdisOpenConfigurationKeyByIndex(&Status,Configurat ionHandle,i++,&KeyName,&KeyHandle);
> if(Status != NDIS_STATUS_SUCCESS) break;
>
> DbgPrint("key = %ws\n",KeyName.Buffer);
Use the %wZ format: DbgPrint("key = %wZ\n", &KeyName);
Regards,
--pa