JavaMan
JavaMan

Reputation: 5054

How DeviceIoControl Returns a Null Terminated String from a Device Driver

Some drivers return a structure thru DeviceIoControl that contains a null-terminated string, say the symbolic name. Where should be the location of that string? For example, the USB host controller accepts IOCTL_USB_GET_ROOT_HUB_NAME (http://msdn.microsoft.com/en-us/library/ff537326(v=VS.85).aspx)which accepts a buffer to USB_HCD_DRIVERKEY_NAME structure as the output. On a closer look, the DriverKeyName field of that structure http://msdn.microsoft.com/en-us/library/ff539325(v=VS.85).aspxis just an array with 1 element of WCHAR type. Where should be the actual driver key name be?

Upvotes: 0

Views: 890

Answers (1)

Luke
Luke

Reputation: 11431

That's a fairly common pattern on Windows. A struct will have something like WCHAR SomeNameOrPath[1] as the last field. This allows for allocating a large buffer for the struct so that the bytes immediately after the struct can contain the rest of the string.

Upvotes: 3

Related Questions