“I just got nothing” is user talk. Talk like a programmer. Run your app in
a debugger, set a breakpoint after the call to
SetupDiGetDeviceRegistryProperty. Then examine the variables that were
returned to you, the return value of SetupDiGetDeviceRegistryProperty, and
if the return value is FALSE, then also evaluate GetLastError(). If these
values don’t show you what the problem is, then post the values to the list,
and we will try to help you.
Judging from the code you have posted, you are not checking the return value
of the function. You must do this. If the function returns FALSE, then it
has failed, and the contents of the return buffer (szFriendlyName) are
undefined. (The buffer may have been overwritten, or it may not, or it may
contain “GREEN CHEESE” over and over.) If you are not checking the return
value, you are simply not programming, only stumbling in the dark. If you
are checking the return value, and it is FALSE, then what is the value of
GetLastError()?
Also note that you’ve committed a very basic programming error. You are
passing an uninitialized pointer to SetupDiGetDeviceRegistryProperty,
specifically dwRegType. dwRegType needs to be a local variable of type
DWORD, NOT “DWORD*”. “DWORD*” is a pointer to a DWORD, but you have not
initialized the pointer. When your code calls
SetupDiGetDeviceRegistryProperty, it will pass stack noise as the pointer to
the registry type, and SetupDiGetDeviceRegistryProperty will then store the
registry type of the property in a random pointer. This will cause
mysterious errors and crashes that are difficult to predict or discover.
Instead, declare the variable as “DWORD dwRegType;” and pass “&dwRegType” to
SetupDiGetDeviceRegistryProperty. This is a basic C issue.
– arlie
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Harsha Inamdar
Sent: Friday, March 31, 2006 1:58 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How to extract a device or driver’s name?
I just got nothing. I am trying to extract this data in MFC app in a combo
box, but combo box is empty.
Thanks,
Harsha
Peter Wieland wrote:
what did you get? Error? zero data?
-p
________________________________
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Harsha Inamdar
Sent: Friday, March 31, 2006 10:13 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How to extract a device or driver’s name?
Hi,
Thank you. I used first SPDRP_FRIENDLYNAME property & then
SPDRP_DEVICEDESC but both of them didn’t extract any data.
Any suggestions? These are the parameters:
DWORD dwRegType;
SetupDiGetDeviceRegistryProperty(pHeader->hDevInfo,
&pHeader->pInfo[i].DeviceInfoData,
SPDRP_DEVICEDESC,
dwRegType,
(BYTE) szFriendlyName,
2096,
NULL);
Thanks,
Harsha