Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Vista Drivers > Why SetupDiEnumDeviceInterfaces fails after SetupDiGetClassDevs success?

Reply
Thread Tools Display Modes

Why SetupDiEnumDeviceInterfaces fails after SetupDiGetClassDevs success?

 
 
Pavel A.
Guest
Posts: n/a

 
      08-10-2010
I have a strange problem with the "classic" device interface
enumeration code (see below).
It works on all WinXP machines we tried it on, except one.
Unfortunately that is a customer's machine so I can't hack it freely,
need some concrete ideas to act upon.

In short, I call SetupDiGetClassDevs(&MY_GUID,... DIGCF_INTERFACEDEVICE)
to get devices with my interface. There is exactly one such device,
created by my driver. This call returns success.
Then I call SetupDiEnumDeviceInterfaces again for my interface GUID -
and it fails with GetLastError=ERROR_NO_MORE_ITEMS ???
I know that the driver successfully enabled this interface, it
shows up in the registry, with correct reference count and so on.

What can be wrong here? Why SetupDiEnumDeviceInterfaces can fail?
This machine is loaded with lots of various software, but generally behaves
well.

The function below is in a DLL, loaded by a console app, both compiled wih
VC2005 .

Regards,
Pavel

---------- code -------
#include <windows.h>
#include <stdio.h>
#include <initguid.h>
#include <setupapi.h>
#pragma comment(lib, "setupapi")

#define _MAX_DEVINTERFACE_NAME_CCH 512

int openDriver( HANDLE *hnd )
{
// Get list of devices with our class GUID:
HDEVINFO classDevs = SetupDiGetClassDevs( &MY_GUID,
NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE );

if ( (INVALID_HANDLE_VALUE == classDevs) || (NULL == classDevs) )
{
dprintWarn("No supported devices found\n");
return -1;
}

SP_DEVICE_INTERFACE_DATA ifdata;
ifdata.cbSize = sizeof(ifdata);
if( !SetupDiEnumDeviceInterfaces(classDevs, NULL, &MY_GUID, 0,
&ifdata) )
{
//<<< HERE IT FAILS GetLastError=ERROR_NO_MORE_ITEMS
dprintWarn("OpenDriver: No supported devices found\n");
SetupDiDestroyDeviceInfoList(classDevs);
return -2;
}

// Get the name for CreateFile
..............................
}


 
Reply With Quote
 
 
 
 
Thomas F. Divine
Guest
Posts: n/a

 
      08-10-2010
Looks OK to me.

Have you tried fetching DeviceInfoData first? Don't know how it could make
any difference, but...

Thomas F. Divine


"Pavel A." <> wrote in message
news:26A52F8D-7AC2-42F5-B313-...
> I have a strange problem with the "classic" device interface
> enumeration code (see below).
> It works on all WinXP machines we tried it on, except one.
> Unfortunately that is a customer's machine so I can't hack it freely,
> need some concrete ideas to act upon.
>
> In short, I call SetupDiGetClassDevs(&MY_GUID,... DIGCF_INTERFACEDEVICE)
> to get devices with my interface. There is exactly one such device,
> created by my driver. This call returns success.
> Then I call SetupDiEnumDeviceInterfaces again for my interface GUID -
> and it fails with GetLastError=ERROR_NO_MORE_ITEMS ???
> I know that the driver successfully enabled this interface, it
> shows up in the registry, with correct reference count and so on.
>
> What can be wrong here? Why SetupDiEnumDeviceInterfaces can fail?
> This machine is loaded with lots of various software, but generally
> behaves well.
>
> The function below is in a DLL, loaded by a console app, both compiled wih
> VC2005 .
>
> Regards,
> Pavel
>
> ---------- code -------
> #include <windows.h>
> #include <stdio.h>
> #include <initguid.h>
> #include <setupapi.h>
> #pragma comment(lib, "setupapi")
>
> #define _MAX_DEVINTERFACE_NAME_CCH 512
>
> int openDriver( HANDLE *hnd )
> {
> // Get list of devices with our class GUID:
> HDEVINFO classDevs = SetupDiGetClassDevs( &MY_GUID,
> NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE );
>
> if ( (INVALID_HANDLE_VALUE == classDevs) || (NULL == classDevs) )
> {
> dprintWarn("No supported devices found\n");
> return -1;
> }
>
> SP_DEVICE_INTERFACE_DATA ifdata;
> ifdata.cbSize = sizeof(ifdata);
> if( !SetupDiEnumDeviceInterfaces(classDevs, NULL, &MY_GUID, 0,
> &ifdata) )
> {
> //<<< HERE IT FAILS GetLastError=ERROR_NO_MORE_ITEMS
> dprintWarn("OpenDriver: No supported devices found\n");
> SetupDiDestroyDeviceInfoList(classDevs);
> return -2;
> }
>
> // Get the name for CreateFile
> ..............................
> }
>
>

 
Reply With Quote
 
Pavel A.
Guest
Posts: n/a

 
      08-10-2010
"Thomas F. Divine" <tdivineATpcausaDOTcom> wrote in message
news:2EE65CA0-4985-4813-8AAE-...
> Looks OK to me.


For me too... and it even works on many machines...

> Have you tried fetching DeviceInfoData first? Don't know how it could make
> any difference, but...


Thanks, Thomas, will try.
By the way, when I looked for the GetLastError symbolic name,
103 is ERROR_NO_MORE_ITEMS, but it is also STATUS_PENDING
as NTSTATUS... does this make any sense?

Thanks.
-- pa

> Thomas F. Divine
>
>
> "Pavel A." <> wrote in message
> news:26A52F8D-7AC2-42F5-B313-...
>> I have a strange problem with the "classic" device interface
>> enumeration code (see below).
>> It works on all WinXP machines we tried it on, except one.
>> Unfortunately that is a customer's machine so I can't hack it freely,
>> need some concrete ideas to act upon.
>>
>> In short, I call SetupDiGetClassDevs(&MY_GUID,... DIGCF_INTERFACEDEVICE)
>> to get devices with my interface. There is exactly one such device,
>> created by my driver. This call returns success.
>> Then I call SetupDiEnumDeviceInterfaces again for my interface GUID -
>> and it fails with GetLastError=ERROR_NO_MORE_ITEMS ???
>> I know that the driver successfully enabled this interface, it
>> shows up in the registry, with correct reference count and so on.
>>
>> What can be wrong here? Why SetupDiEnumDeviceInterfaces can fail?
>> This machine is loaded with lots of various software, but generally
>> behaves well.
>>
>> The function below is in a DLL, loaded by a console app, both compiled
>> wih VC2005 .
>>
>> Regards,
>> Pavel
>>
>> ---------- code -------
>> #include <windows.h>
>> #include <stdio.h>
>> #include <initguid.h>
>> #include <setupapi.h>
>> #pragma comment(lib, "setupapi")
>>
>> #define _MAX_DEVINTERFACE_NAME_CCH 512
>>
>> int openDriver( HANDLE *hnd )
>> {
>> // Get list of devices with our class GUID:
>> HDEVINFO classDevs = SetupDiGetClassDevs( &MY_GUID,
>> NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE );
>>
>> if ( (INVALID_HANDLE_VALUE == classDevs) || (NULL == classDevs) )
>> {
>> dprintWarn("No supported devices found\n");
>> return -1;
>> }
>>
>> SP_DEVICE_INTERFACE_DATA ifdata;
>> ifdata.cbSize = sizeof(ifdata);
>> if( !SetupDiEnumDeviceInterfaces(classDevs, NULL, &MY_GUID, 0,
>> &ifdata) )
>> {
>> //<<< HERE IT FAILS GetLastError=ERROR_NO_MORE_ITEMS
>> dprintWarn("OpenDriver: No supported devices found\n");
>> SetupDiDestroyDeviceInfoList(classDevs);
>> return -2;
>> }
>>
>> // Get the name for CreateFile
>> ..............................
>> }
>>



 
Reply With Quote
 
Thomas F. Divine
Guest
Posts: n/a

 
      08-11-2010
Maybe there is confusion between Win32 error codes (WinError.h) and NT
status codes (NTStatus.h).

Perhaps pending is correct in this case because of some delay...

Thos


"Pavel A." <> wrote in message
news:A7E43CB5-B631-4C1C-B73A-...
> "Thomas F. Divine" <tdivineATpcausaDOTcom> wrote in message
> news:2EE65CA0-4985-4813-8AAE-...
>> Looks OK to me.

>
> For me too... and it even works on many machines...
>
>> Have you tried fetching DeviceInfoData first? Don't know how it could
>> make any difference, but...

>
> Thanks, Thomas, will try.
> By the way, when I looked for the GetLastError symbolic name,
> 103 is ERROR_NO_MORE_ITEMS, but it is also STATUS_PENDING
> as NTSTATUS... does this make any sense?
>
> Thanks.
> -- pa
>
>> Thomas F. Divine
>>
>>
>> "Pavel A." <> wrote in message
>> news:26A52F8D-7AC2-42F5-B313-...
>>> I have a strange problem with the "classic" device interface
>>> enumeration code (see below).
>>> It works on all WinXP machines we tried it on, except one.
>>> Unfortunately that is a customer's machine so I can't hack it freely,
>>> need some concrete ideas to act upon.
>>>
>>> In short, I call SetupDiGetClassDevs(&MY_GUID,... DIGCF_INTERFACEDEVICE)
>>> to get devices with my interface. There is exactly one such device,
>>> created by my driver. This call returns success.
>>> Then I call SetupDiEnumDeviceInterfaces again for my interface GUID -
>>> and it fails with GetLastError=ERROR_NO_MORE_ITEMS ???
>>> I know that the driver successfully enabled this interface, it
>>> shows up in the registry, with correct reference count and so on.
>>>
>>> What can be wrong here? Why SetupDiEnumDeviceInterfaces can fail?
>>> This machine is loaded with lots of various software, but generally
>>> behaves well.
>>>
>>> The function below is in a DLL, loaded by a console app, both compiled
>>> wih VC2005 .
>>>
>>> Regards,
>>> Pavel
>>>
>>> ---------- code -------
>>> #include <windows.h>
>>> #include <stdio.h>
>>> #include <initguid.h>
>>> #include <setupapi.h>
>>> #pragma comment(lib, "setupapi")
>>>
>>> #define _MAX_DEVINTERFACE_NAME_CCH 512
>>>
>>> int openDriver( HANDLE *hnd )
>>> {
>>> // Get list of devices with our class GUID:
>>> HDEVINFO classDevs = SetupDiGetClassDevs( &MY_GUID,
>>> NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE );
>>>
>>> if ( (INVALID_HANDLE_VALUE == classDevs) || (NULL == classDevs) )
>>> {
>>> dprintWarn("No supported devices found\n");
>>> return -1;
>>> }
>>>
>>> SP_DEVICE_INTERFACE_DATA ifdata;
>>> ifdata.cbSize = sizeof(ifdata);
>>> if( !SetupDiEnumDeviceInterfaces(classDevs, NULL, &MY_GUID, 0,
>>> &ifdata) )
>>> {
>>> //<<< HERE IT FAILS GetLastError=ERROR_NO_MORE_ITEMS
>>> dprintWarn("OpenDriver: No supported devices found\n");
>>> SetupDiDestroyDeviceInfoList(classDevs);
>>> return -2;
>>> }
>>>
>>> // Get the name for CreateFile
>>> ..............................
>>> }
>>>

>
>

 
Reply With Quote
 
Pavel A.
Guest
Posts: n/a

 
      08-12-2010
Catched the culprit: Logitech USB camera driver LVUSBsta.sys.
It changed the security for built-in class Unknown ("Other devices") so that
only Local system can access it.
No idea why they did this.
Since my driver is in Unknown class, it was affected.

I've deleted the Unknown class from registry, rebooted and noticed that
somebody created it again.
The rest was simple, thanks to Sysinternals procmon: I've set it to log
registry writes on the class key during boot,
restarted again and the Logitech driver was catched with red hands.

The fix was to specify security for my device in the INF, so it won't
inherit it from the (hacked) class.
Back to basics, every day

Regards,
-- pa



"Thomas F. Divine" <tdivineATpcausaDOTcom> wrote in message
news:3820CC08-A9F8-4618-938D-...
> Maybe there is confusion between Win32 error codes (WinError.h) and NT
> status codes (NTStatus.h).
>
> Perhaps pending is correct in this case because of some delay...
>
> Thos
>
>
> "Pavel A." <> wrote in message
> news:A7E43CB5-B631-4C1C-B73A-...
>> "Thomas F. Divine" <tdivineATpcausaDOTcom> wrote in message
>> news:2EE65CA0-4985-4813-8AAE-...
>>> Looks OK to me.

>>
>> For me too... and it even works on many machines...
>>
>>> Have you tried fetching DeviceInfoData first? Don't know how it could
>>> make any difference, but...

>>
>> Thanks, Thomas, will try.
>> By the way, when I looked for the GetLastError symbolic name,
>> 103 is ERROR_NO_MORE_ITEMS, but it is also STATUS_PENDING
>> as NTSTATUS... does this make any sense?
>>
>> Thanks.
>> -- pa
>>
>>> Thomas F. Divine
>>>
>>>
>>> "Pavel A." <> wrote in message
>>> news:26A52F8D-7AC2-42F5-B313-...
>>>> I have a strange problem with the "classic" device interface
>>>> enumeration code (see below).
>>>> It works on all WinXP machines we tried it on, except one.
>>>> Unfortunately that is a customer's machine so I can't hack it freely,
>>>> need some concrete ideas to act upon.
>>>>
>>>> In short, I call SetupDiGetClassDevs(&MY_GUID,...
>>>> DIGCF_INTERFACEDEVICE)
>>>> to get devices with my interface. There is exactly one such device,
>>>> created by my driver. This call returns success.
>>>> Then I call SetupDiEnumDeviceInterfaces again for my interface GUID -
>>>> and it fails with GetLastError=ERROR_NO_MORE_ITEMS ???
>>>> I know that the driver successfully enabled this interface, it
>>>> shows up in the registry, with correct reference count and so on.
>>>>
>>>> What can be wrong here? Why SetupDiEnumDeviceInterfaces can fail?
>>>> This machine is loaded with lots of various software, but generally
>>>> behaves well.
>>>>
>>>> The function below is in a DLL, loaded by a console app, both compiled
>>>> wih VC2005 .
>>>>
>>>> Regards,
>>>> Pavel
>>>>
>>>> ---------- code -------
>>>> #include <windows.h>
>>>> #include <stdio.h>
>>>> #include <initguid.h>
>>>> #include <setupapi.h>
>>>> #pragma comment(lib, "setupapi")
>>>>
>>>> #define _MAX_DEVINTERFACE_NAME_CCH 512
>>>>
>>>> int openDriver( HANDLE *hnd )
>>>> {
>>>> // Get list of devices with our class GUID:
>>>> HDEVINFO classDevs = SetupDiGetClassDevs( &MY_GUID,
>>>> NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE );
>>>>
>>>> if ( (INVALID_HANDLE_VALUE == classDevs) || (NULL == classDevs) )
>>>> {
>>>> dprintWarn("No supported devices found\n");
>>>> return -1;
>>>> }
>>>>
>>>> SP_DEVICE_INTERFACE_DATA ifdata;
>>>> ifdata.cbSize = sizeof(ifdata);
>>>> if( !SetupDiEnumDeviceInterfaces(classDevs, NULL, &MY_GUID, 0,
>>>> &ifdata) )
>>>> {
>>>> //<<< HERE IT FAILS GetLastError=ERROR_NO_MORE_ITEMS
>>>> dprintWarn("OpenDriver: No supported devices found\n");
>>>> SetupDiDestroyDeviceInfoList(classDevs);
>>>> return -2;
>>>> }
>>>>
>>>> // Get the name for CreateFile
>>>> ..............................
>>>> }
>>>>

>>
>>

 
Reply With Quote
 
Thomas F. Divine
Guest
Posts: n/a

 
      08-12-2010
Good sleuthing, Pavel. I'll remember that one.

Thomas

"Pavel A." <> wrote in message
news:245DE109-1B84-4D14-A4EF-...
> Catched the culprit: Logitech USB camera driver LVUSBsta.sys.
> It changed the security for built-in class Unknown ("Other devices") so
> that only Local system can access it.
> No idea why they did this.
> Since my driver is in Unknown class, it was affected.
>
> I've deleted the Unknown class from registry, rebooted and noticed that
> somebody created it again.
> The rest was simple, thanks to Sysinternals procmon: I've set it to log
> registry writes on the class key during boot,
> restarted again and the Logitech driver was catched with red hands.
>
> The fix was to specify security for my device in the INF, so it won't
> inherit it from the (hacked) class.
> Back to basics, every day
>
> Regards,
> -- pa
>
>
>
> "Thomas F. Divine" <tdivineATpcausaDOTcom> wrote in message
> news:3820CC08-A9F8-4618-938D-...
>> Maybe there is confusion between Win32 error codes (WinError.h) and NT
>> status codes (NTStatus.h).
>>
>> Perhaps pending is correct in this case because of some delay...
>>
>> Thos
>>
>>
>> "Pavel A." <> wrote in message
>> news:A7E43CB5-B631-4C1C-B73A-...
>>> "Thomas F. Divine" <tdivineATpcausaDOTcom> wrote in message
>>> news:2EE65CA0-4985-4813-8AAE-...
>>>> Looks OK to me.
>>>
>>> For me too... and it even works on many machines...
>>>
>>>> Have you tried fetching DeviceInfoData first? Don't know how it could
>>>> make any difference, but...
>>>
>>> Thanks, Thomas, will try.
>>> By the way, when I looked for the GetLastError symbolic name,
>>> 103 is ERROR_NO_MORE_ITEMS, but it is also STATUS_PENDING
>>> as NTSTATUS... does this make any sense?
>>>
>>> Thanks.
>>> -- pa
>>>
>>>> Thomas F. Divine
>>>>
>>>>
>>>> "Pavel A." <> wrote in message
>>>> news:26A52F8D-7AC2-42F5-B313-...
>>>>> I have a strange problem with the "classic" device interface
>>>>> enumeration code (see below).
>>>>> It works on all WinXP machines we tried it on, except one.
>>>>> Unfortunately that is a customer's machine so I can't hack it freely,
>>>>> need some concrete ideas to act upon.
>>>>>
>>>>> In short, I call SetupDiGetClassDevs(&MY_GUID,...
>>>>> DIGCF_INTERFACEDEVICE)
>>>>> to get devices with my interface. There is exactly one such device,
>>>>> created by my driver. This call returns success.
>>>>> Then I call SetupDiEnumDeviceInterfaces again for my interface GUID -
>>>>> and it fails with GetLastError=ERROR_NO_MORE_ITEMS ???
>>>>> I know that the driver successfully enabled this interface, it
>>>>> shows up in the registry, with correct reference count and so on.
>>>>>
>>>>> What can be wrong here? Why SetupDiEnumDeviceInterfaces can fail?
>>>>> This machine is loaded with lots of various software, but generally
>>>>> behaves well.
>>>>>
>>>>> The function below is in a DLL, loaded by a console app, both compiled
>>>>> wih VC2005 .
>>>>>
>>>>> Regards,
>>>>> Pavel
>>>>>
>>>>> ---------- code -------
>>>>> #include <windows.h>
>>>>> #include <stdio.h>
>>>>> #include <initguid.h>
>>>>> #include <setupapi.h>
>>>>> #pragma comment(lib, "setupapi")
>>>>>
>>>>> #define _MAX_DEVINTERFACE_NAME_CCH 512
>>>>>
>>>>> int openDriver( HANDLE *hnd )
>>>>> {
>>>>> // Get list of devices with our class GUID:
>>>>> HDEVINFO classDevs = SetupDiGetClassDevs( &MY_GUID,
>>>>> NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE );
>>>>>
>>>>> if ( (INVALID_HANDLE_VALUE == classDevs) || (NULL == classDevs) )
>>>>> {
>>>>> dprintWarn("No supported devices found\n");
>>>>> return -1;
>>>>> }
>>>>>
>>>>> SP_DEVICE_INTERFACE_DATA ifdata;
>>>>> ifdata.cbSize = sizeof(ifdata);
>>>>> if( !SetupDiEnumDeviceInterfaces(classDevs, NULL, &MY_GUID, 0,
>>>>> &ifdata) )
>>>>> {
>>>>> //<<< HERE IT FAILS GetLastError=ERROR_NO_MORE_ITEMS
>>>>> dprintWarn("OpenDriver: No supported devices found\n");
>>>>> SetupDiDestroyDeviceInfoList(classDevs);
>>>>> return -2;
>>>>> }
>>>>>
>>>>> // Get the name for CreateFile
>>>>> ..............................
>>>>> }
>>>>>
>>>
>>>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem running .wmv , when a file system filter driver is install Ajay Windows Vista Drivers 3 05-07-2010 05:45 AM
Clean Install of XP Fails after Vista Install Success John Kotuby Windows Vista Installation 5 10-11-2007 09:32 AM
No sound with SoundMax on Vista RTM Yuval Rakavy Windows Vista Hardware 5 03-13-2007 01:27 AM
Patch fails to update files, reports success Trent Windows Vista Installation 2 07-03-2006 11:47 PM
MSI Patch reprots success, but fails to update any files Trent Windows Vista Installation 1 07-03-2006 11:45 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59