/// <summary>
/// Gets a descriptor from the device. See <see cref="DescriptorType"/> for more information.
/// </summary>
/// <param name="descriptorType">The descriptor type ID to retrieve; this is usually one of the <see cref="DescriptorType"/> enumerations.</param>
/// <param name="index">Descriptor index.</param>
/// <param name="langId">Descriptor language id.</param>
/// <param name="buffer">Memory to store the returned descriptor in.</param>
/// <param name="bufferLength">Length of the buffer parameter in bytes.</param>
/// <param name="transferLength">The number of bytes transferred to buffer upon success.</param>
/// <returns>True on success.</returns>
public virtual bool GetDescriptor(byte descriptorType, byte index, short langId, IntPtr buffer, int bufferLength, out int transferLength)
{
transferLength = 0;
bool wasOpen = IsOpen;
if (!wasOpen)
{
Open();
}
if (!IsOpen)
{
return(false);
}
bool bSuccess = mUsbApi.GetDescriptor(mUsbHandle, descriptorType, index, (ushort)langId, buffer, bufferLength, out transferLength);
if (!bSuccess)
{
UsbError.Error(ErrorCode.Win32Error, Marshal.GetLastWin32Error(), "GetDescriptor", this);
}
if (!wasOpen && IsOpen)
{
Close();
}
return(bSuccess);
}