SetupDiGetClassDevs does not returns present device

For some reason some USB(in my case) devices in not returned by SetupDiGetClassDevs with (DIGCF_ALLCLASSES | DIGCF_PRESENT) falgs. Device is present in system and is showed up as connected by device manager and devcon. And the device is returned without DIGCF_PRESENT flag.
I see the same problem for USBDeview prograam it also showed device as not connected. What can be the reason?

My sample code:

/*****************************************************************************
I N C L U D E S
*****************************************************************************/
#include <windows.h>
#include <setupapi.h>
#include <usbioctl.h>

#include <stdio.h>
#include <tchar.h>
#include <usbiodef.h>

#ifdef DEBUG
#undef DBG
#define DBG 1
#endif

#if DBG
#define OOPS() Oops( FILE , LINE )
#else
#define OOPS()
#endif

#define ALLOC(dwBytes) GlobalAlloc(GPTR,(dwBytes))

#define REALLOC(hMem, dwBytes) GlobalReAlloc((hMem), (dwBytes), (GMEM_MOVEABLE|GMEM_ZEROINIT))

#define FREE(hMem) GlobalFree((hMem))

#define CHECKFORLEAKS()

Success(return == TRUE)
BOOL
GetDeviceProperty(
In HDEVINFO DeviceInfoSet,
In PSP_DEVINFO_DATA DeviceInfoData,
In DWORD Property,
Outptr LPTSTR *ppBuffer
)
{
BOOL bResult;
DWORD requiredLength = 0;
DWORD lastError;

if(ppBuffer == NULL)
{
return FALSE;
}

*ppBuffer = NULL;

bResult = SetupDiGetDeviceRegistryProperty(DeviceInfoSet,
DeviceInfoData,
Property,
NULL,
NULL,
0,
&requiredLength);
lastError = GetLastError();

if((requiredLength == 0) || (bResult != FALSE && lastError != ERROR_INSUFFICIENT_BUFFER))
{
return FALSE;
}

*ppBuffer = ALLOC(requiredLength);

if(*ppBuffer == NULL)
{
return FALSE;
}

bResult = SetupDiGetDeviceRegistryProperty(DeviceInfoSet,
DeviceInfoData,
Property,
NULL,
(PBYTE)*ppBuffer,
requiredLength,
&requiredLength);
if(bResult == FALSE)
{
FREE(*ppBuffer);
ppBuffer = NULL;
return FALSE;
}

return TRUE;
}

void
EnumerateAllDevices(
)
{
HDEVINFO deviceInfo = NULL;
LPGUID Guid = (LPGUID)&GUID_DEVINTERFACE_USB_DEVICE;
// Getting all present devices
deviceInfo = SetupDiGetClassDevs(Guid,
NULL,
NULL,
(DIGCF_ALLCLASSES | DIGCF_PRESENT));

if(deviceInfo != INVALID_HANDLE_VALUE)
{
ULONG index;
DWORD error;

error = 0;
index = 0;

while(error != ERROR_NO_MORE_ITEMS)
{

BOOL success;
SP_DEVINFO_DATA infoData;
ZeroMemory(&infoData, sizeof(SP_DEVINFO_DATA));
PWSTR DeviceDescName = NULL;
infoData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);

success = SetupDiEnumDeviceInfo(deviceInfo,
index,
&infoData);

index++;

if(success == FALSE)
{
error = GetLastError();

if(error != ERROR_NO_MORE_ITEMS)
{
//OOPS();
}
}
else
{
BOOL bResult;

bResult = GetDeviceProperty(deviceInfo,
&infoData,
SPDRP_DEVICEDESC,
&DeviceDescName);
if(bResult == FALSE)
{
//OOPS();
break;
}

printf(“DeviceDescName = %s\n”, DeviceDescName);
}
}
}
}

int _tmain(int argc, _TCHAR
argv)
{
EnumerateAllDevices();
return 0;
}</usbiodef.h></tchar.h></stdio.h></usbioctl.h></setupapi.h></windows.h>

xxxxx@gmail.com wrote:

For some reason some USB(in my case) devices in not returned by SetupDiGetClassDevs with (DIGCF_ALLCLASSES | DIGCF_PRESENT) falgs. Device is present in system and is showed up as connected by device manager and devcon. And the device is returned without DIGCF_PRESENT flag.
I see the same problem for USBDeview prograam it also showed device as not connected. What can be the reason?

What kind of devices are missing? Do you get different results if you
run the app as administrator? Is it possible the device has some kind
of protocol issue that is causing it to come and go?

Devcon uses those exact same SetupDi APIs, so if Devcon can see it, then
it is “seeable”. You might need to check the source code for the
operation you’re doing to see if they are setting some other flag.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

On 18-Aug-2015 16:50, xxxxx@gmail.com wrote:

For some reason some USB(in my case) devices in not returned by SetupDiGetClassDevs with (DIGCF_ALLCLASSES | DIGCF_PRESENT) falgs. Device is present in system and is showed up as connected by device manager and devcon. And the device is returned without DIGCF_PRESENT flag.
I see the same problem for USBDeview prograam it also showed device as not connected. What can be the reason?

If your Windows in 64-bit, make sure to build your program also as 64-bit.

– pa

Does the registry key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\YOUR_VID&YOUR_PID exist? Do you see DeviceDesc value there? Which type is it?

< run the app as administrator? Is it possible the device has some kind
< of protocol issue that is causing it to come and go?

I am talking about SAMSUNG Android ADB Interface - Android Debug Bridge(it is a child of SAMSUNG Mobile USB Composite Device). The adb is working properly, devices is not come and go.
I have run as admin also with the same result.

< If your Windows in 64-bit, make sure to build your program also as 64-bit.
the same for x64 app

< Does the registry key
< HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\YOUR_VID&YOUR_PID exist? Do you see DeviceDesc value there? Which type is it?

Yes, it is @oem36.inf,%compositeadbinterface%;SAMSUNG Android ADB Interface

And as I say I can find device without DIGCF_PRESENT flag… i can’t get why.

Perhaps the adb driver is not exposing this device interface for itself or children. The interface you had in your code is only enabled by the Usb core drivers, it doesn’t extend to the entire device subtree

Sent from Outlook Mailhttp: for Windows 10

From: xxxxx@gmail.com
Sent: Wednesday, August 19, 2015 10:28 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] SetupDiGetClassDevs does not returns present device

< run the app as administrator? Is it possible the device has some kind
< of protocol issue that is causing it to come and go?

I am talking about SAMSUNG Android ADB Interface - Android Debug Bridge(it is a child of SAMSUNG Mobile USB Composite Device). The adb is working properly, devices is not come and go.
I have run as admin also with the same result.

< If your Windows in 64-bit, make sure to build your program also as 64-bit.
the same for x64 app

< Does the registry key
< HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\YOUR_VID&YOUR_PID exist? Do you see DeviceDesc value there? Which type is it?

Yes, it is @oem36.inf,%compositeadbinterface%;SAMSUNG Android ADB Interface

And as I say I can find device without DIGCF_PRESENT flag… i can’t get why.


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer</http:>

I have tried also
deviceInfo = SetupDiGetClassDevs(NULL, NULL, NULL,
(DIGCF_ALLCLASSES | DIGCF_PRESENT));

(with NULL ClassGuid parameter) - that should “return devices for all device setup classes” but the same no such device with DIGCF_PRESENT.

xxxxx@gmail.com wrote:

I have tried also
deviceInfo = SetupDiGetClassDevs(NULL, NULL, NULL,
(DIGCF_ALLCLASSES | DIGCF_PRESENT));

(with NULL ClassGuid parameter) - that should “return devices for all device setup classes” but the same no such device with DIGCF_PRESENT.

Does “devcon find” find the device? If so, then you’re doing something
wrong. It uses SetupDiGetClassDevs.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

(I know it’s been a few years, but even after all that time
this question manages to appear on the first page of some
search engines when “DIGCF_PRESENT” is included.
THIS is a great example of what an “Obscure question” is! :smile: )
.
For just USB devices, I’d go with:

    hDevInfo = SetupDiGetClassDevsW(NULL, L"USB", NULL, DIGCF_ALLCLASSES | DIGCF_PRESENT);

Sigh.

Discussion closed. Start a new discussion if you want to continue this issue.

Peter