L
LeoAyala
Guest
I'm calling DeviceIoControl to retrieve STORAGE_DEVICE_DESCRIPTOR data. The MSDN site shows the definition of the structure in which it includes a byte-array. It declares the byte array size to 1 byte and it states that it serves as a placeholder for the actual array that will be returned from the call. In my c# app I create my struct matching the definition in MSDN site.
[StructLayout(LayoutKind.Sequential)]
public class SSTORAGE_DEVICE_DESCRIPTOR
{
public uint Version;
public uint Size;
public byte DeviceType;
public byte DeviceTypeModifier;
public byte RemovableMedia;
public byte CommandQueueing;
public uint VendorIdOffset;
public uint ProductIdOffset;
public uint ProductRevisionOffset;
public uint SerialNumberOffset;
public byte BusType;
public uint RawPropertiesLength;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
public byte[] RawDeviceProperties;
}
Since the array size if variable, the first call to DeviceIoControl is used to determine the size of the output buffer that I need to allocate. This call succeeds and I allocate a buffer (IntPtr) of the proper length and make the call to DeviceIoControl to get the storage device descriptor data. This also succeeds and I can see the structure data except for RawDeviceProperties. I cant access more than just the one byte. However, if I copy the output buffer (IntPtr) to a byte-array, I can see that the extra data that got appended to the structure is there.
What is the best way to access the data that got appended to this structure?
Thanks.
LA
Continue reading...
[StructLayout(LayoutKind.Sequential)]
public class SSTORAGE_DEVICE_DESCRIPTOR
{
public uint Version;
public uint Size;
public byte DeviceType;
public byte DeviceTypeModifier;
public byte RemovableMedia;
public byte CommandQueueing;
public uint VendorIdOffset;
public uint ProductIdOffset;
public uint ProductRevisionOffset;
public uint SerialNumberOffset;
public byte BusType;
public uint RawPropertiesLength;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
public byte[] RawDeviceProperties;
}
Since the array size if variable, the first call to DeviceIoControl is used to determine the size of the output buffer that I need to allocate. This call succeeds and I allocate a buffer (IntPtr) of the proper length and make the call to DeviceIoControl to get the storage device descriptor data. This also succeeds and I can see the structure data except for RawDeviceProperties. I cant access more than just the one byte. However, if I copy the output buffer (IntPtr) to a byte-array, I can see that the extra data that got appended to the structure is there.
What is the best way to access the data that got appended to this structure?
Thanks.
LA
Continue reading...