Hi all I have a tricky one here..
I have some code I'm using to interact with USB devices (windows driver kit). I'm targeting "USB MASS Storage" and hopefully "USB Composite Device" basicaly I want any device that has a drive letter where i can read/write from.

- basicaly i need to know the drive letter of the usb device
- the code works for some devices, USB mass storage device having a GUID of
const string GUID_DEVINTERFACE_DISK = "53f56307-b6bf-11d0-94f2-00a0c91efb8b";
devices are thumb drives, removable HD's things that are class "USB MASS Storage"

however a USB composite device has a different GUID of
const string TEST_GUID = "36fc9e60-c465-11cf-8056-444553540000"; and the code fails to return the device.
devices are Phones... class of "USB Composite Device"

so i changed the GUID and ran the code and it did not find any device using the GUID for composite device... so it must be checking something else as well... here is the method that gets a device by its drive letter... please help me out in getting it to work with compisite devices as well.

or at least point show me the general area what needs to be changed.

im fairly new to c# and i dont understand this low level stuff....

thanks...

this method accepts a drive letter and attempts to find a device matching the drive letter.
seems like it will work right, phones have drive letter.. but no it looks at GUID etc..

--- code ---

// usb mass storage device
const string GUID_DEVINTERFACE_DISK = "53f56307-b6bf-11d0-94f2-00a0c91efb8b";
//
// Find a device based upon a Drive Letter
//
static public USBDevice FindDriveLetter(string DriveLetter)
{
USBDevice FoundDevice = null;
string InstanceID = "";

// We start by getting the unique DeviceNumber of the given
// DriveLetter. We'll use this later to find a matching
// DevicePath "symbolic name"
int DevNum = GetDeviceNumber(@"\\.\" + DriveLetter.TrimEnd('\\'));
if (DevNum < 0)
{
return FoundDevice;
}

Guid DiskGUID = new Guid(GUID_DEVINTERFACE_DISK);

// We start at the "root" of the device tree and look for all
// devices that match the interface GUID of a disk
IntPtr h = SetupDiGetClassDevs(ref DiskGUID, 0, IntPtr.Zero, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
if (h.ToInt32() != INVALID_HANDLE_VALUE)
{
bool Success = true;
int i = 0;
do
{
// create a Device Interface Data structure
SP_DEVICE_INTERFACE_DATA dia = new SP_DEVICE_INTERFACE_DATA();
dia.cbSize = Marshal.SizeOf(dia);

// start the enumeration
Success = SetupDiEnumDeviceInterfaces(h, IntPtr.Zero, ref DiskGUID, i, ref dia);
if (Success)
{
// build a DevInfo Data structure
SP_DEVINFO_DATA da = new SP_DEVINFO_DATA();
da.cbSize = Marshal.SizeOf(da);

// build a Device Interface Detail Data structure
SP_DEVICE_INTERFACE_DETAIL_DATA didd = new SP_DEVICE_INTERFACE_DETAIL_DATA();
didd.cbSize = 4 + Marshal.SystemDefaultCharSize; // trust me

// now we can get some more detailed information
int nRequiredSize = 0;
int nBytes = BUFFER_SIZE;
if (SetupDiGetDeviceInterfaceDetail(h, ref dia, ref didd, nBytes, ref nRequiredSize, ref da))
{
// Now that we have a DevicePath... we can use it to
// generate another DeviceNumber to see if it matches
// the one we're looking for.
if (GetDeviceNumber(didd.DevicePath) == DevNum)
{
// current InstanceID is at the "USBSTOR" level, so we
// need up "move up" one level to get to the "USB" level
IntPtr ptrPrevious;
CM_Get_Parent(out ptrPrevious, da.DevInst, 0);

// Now we get the InstanceID of the USB level device
IntPtr ptrInstanceBuf = Marshal.AllocHGlobal(nBytes);
CM_Get_Device_ID(ptrPrevious, ptrInstanceBuf, nBytes, 0);
InstanceID = Marshal.PtrToStringAuto(ptrInstanceBuf);

Marshal.FreeHGlobal(ptrInstanceBuf);
break;
}
}
}
i++;
} while (Success);
SetupDiDestroyDeviceInfoList(h);
}

// Did we find an InterfaceID of a USB device?
if (InstanceID.StartsWith("USB\\"))
{
FoundDevice = FindDeviceByInstanceID(InstanceID);
}
return FoundDevice;
}