Click here to Skip to main content
15,356,327 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: SetupDiGetDeviceRegistryProperty - buffer size? Pin
Jochen Arndt28-Nov-12 8:19
professionalJochen Arndt28-Nov-12 8:19 
GeneralRe: SetupDiGetDeviceRegistryProperty - buffer size? Pin
Vaclav_29-Nov-12 5:52
MemberVaclav_29-Nov-12 5:52 
GeneralRe: SetupDiGetDeviceRegistryProperty - buffer size? Pin
Jochen Arndt29-Nov-12 6:49
professionalJochen Arndt29-Nov-12 6:49 
GeneralRe: SetupDiGetDeviceRegistryProperty - buffer size? Pin
Vaclav_29-Nov-12 8:23
MemberVaclav_29-Nov-12 8:23 
GeneralRe: SetupDiGetDeviceRegistryProperty - buffer size? Pin
Jochen Arndt29-Nov-12 21:16
professionalJochen Arndt29-Nov-12 21:16 
GeneralRe: SetupDiGetDeviceRegistryProperty - buffer size? Pin
Vaclav_30-Nov-12 2:43
MemberVaclav_30-Nov-12 2:43 
AnswerRe: SetupDiGetDeviceRegistryProperty - buffer size? Pin
Cristian Amarie3-Dec-12 8:58
MemberCristian Amarie3-Dec-12 8:58 
GeneralRe: SetupDiGetDeviceRegistryProperty - buffer size? Pin
Vaclav_3-Dec-12 12:39
MemberVaclav_3-Dec-12 12:39 
<pre lang="text">

Thanks Cristian,
I have actually given up on figuring it out, but here is the latest ( with lots of development comments) and it does work as advertized.
NULL, // (PBYTE)buf, // get size with NULL (PBYTE)buffer, // _Out_opt_ PBYTE PropertyBuffer,
0, // sizeof(buf),
With these two parameters set this way , the function fails and returns / sets the &nSize.

I am not checking the errors anymore and just run the same function again with results and it returns true.

The rest of it is just an execise to see the “properties” . And it works.

I am going to check my original code , it is possible that I did forget the cast (PBYTE) buffer, but it is such a mess I am really not looking forward to do that. I was just hoping to delete all the commented out attempts a be done with it. I'll check for unicode too.
Thanks

</pre>






bool C_HWDetect::C_Enumerate()
{
TRACE("\nbool C_HWDetect::C_Enumerate()");

WPARAM wParam; // event wiht parameters !!
CString szClass = "";
/* this monitors changes
DWORD dwFlag = DBT_DEVICEARRIVAL != wParam ?
DIGCF_ALLCLASSES : (DIGCF_ALLCLASSES | DIGCF_PRESENT);
*/

DWORD dwFlag = DIGCF_ALLCLASSES | DIGCF_PRESENT;
HDEVINFO hDevInfo = SetupDiGetClassDevs(NULL,"USB", /* szClass,*/ NULL,dwFlag);
if( INVALID_HANDLE_VALUE == hDevInfo ) {
/*
AfxMessageBox(CString("SetupDiGetClassDevs(): ")
+ _com_error(GetLastError()).ErrorMessage(), MB_ICONEXCLAMATION);
*/
return false;
}

CString szDevId;
SP_DEVINFO_DATA spDevInfoData;
if ( C_FindDevice(hDevInfo, szDevId, spDevInfoData) ) {

DWORD DataT ;
TCHAR buf[MAX_PATH];
DWORD nSize = 0;

bool bResult = SetupDiGetDeviceRegistryProperty(
hDevInfo, // _In_ HDEVINFO DeviceInfoSet,
&spDevInfoData, // _In_ PSP_DEVINFO_DATA DeviceInfoData
SPDRP_DEVICEDESC, // _In_ DWORD Property,
&DataT, // _Out_opt_ PDWORD PropertyRegDataType,
NULL, // (PBYTE)buf, // get size with NULL (PBYTE)buffer, // _Out_opt_ PBYTE PropertyBuffer,
0, // sizeof(buf), // get size with 0 buffersize,
&nSize); // fills buffer size

bResult = SetupDiGetDeviceRegistryProperty(
hDevInfo, // _In_ HDEVINFO DeviceInfoSet,
&spDevInfoData, // _In_ PSP_DEVINFO_DATA DeviceInfoData
SPDRP_DEVICEDESC, // _In_ DWORD Property,
&DataT, // _Out_opt_ PDWORD PropertyRegDataType,
(PBYTE)buf, // get size with NULL (PBYTE)buffer, // _Out_opt_ PBYTE PropertyBuffer,
sizeof(buf), // get size with 0 buffersize,
&nSize); // fills buffer size

for (int iProperty = 0; iProperty != SPDRP_MAXIMUM_PROPERTY; iProperty++)
{
bResult = SetupDiGetDeviceRegistryProperty(hDevInfo, &spDevInfoData,
iProperty /* SPDRP_DEVICEDESC*/ , &DataT, (PBYTE)buf, sizeof(buf), &nSize);


TRACE("\nBuffer Property %i %s ",iProperty, buf);
}
// get Friendly Name or Device Description
if ( SetupDiGetDeviceRegistryProperty(hDevInfo, &spDevInfoData,
SPDRP_DEVICEDESC, &DataT, (PBYTE)buf, sizeof(buf), &nSize) ) {
TRACE("\nBuffer SPDRP_DEVICEDESC %s ",buf);
} else if ( SetupDiGetDeviceRegistryProperty(hDevInfo, &spDevInfoData,
SPDRP_FRIENDLYNAME, &DataT, (PBYTE)buf, sizeof(buf), &nSize) ) {
TRACE("\nBuffer SPDRP_FRIENDLYNAME %s ",buf);
} else {
lstrcpy(buf, _T("Unknown"));
}


There is one unanswered question - this function <b>SetupDiGetDeviceRegistryProperty</b>either returns description or friendly name. How am I suppose to know which one is really valid to ask for???
SetupDiGetDeviceRegistryProperty
GeneralRe: SetupDiGetDeviceRegistryProperty - buffer size? Pin
Cristian Amarie3-Dec-12 17:37
MemberCristian Amarie3-Dec-12 17:37 
GeneralRe: SetupDiGetDeviceRegistryProperty - buffer size? Pin
Cristian Amarie3-Dec-12 18:52
MemberCristian Amarie3-Dec-12 18:52 
GeneralRe: SetupDiGetDeviceRegistryProperty - buffer size? Pin
Vaclav_4-Dec-12 5:58
MemberVaclav_4-Dec-12 5:58 
GeneralRe: SetupDiGetDeviceRegistryProperty - buffer size? Pin
Cristian Amarie4-Dec-12 7:11
MemberCristian Amarie4-Dec-12 7:11 
QuestionShred a folder Pin
MehdiHazrati26-Nov-12 20:52
MemberMehdiHazrati26-Nov-12 20:52 
QuestionRe: Shred a folder Pin
David Crow27-Nov-12 3:57
MemberDavid Crow27-Nov-12 3:57 
AnswerRe: Shred a folder Pin
MehdiHazrati27-Nov-12 4:26
MemberMehdiHazrati27-Nov-12 4:26 
GeneralRe: Shred a folder Pin
Richard MacCutchan27-Nov-12 4:28
mveRichard MacCutchan27-Nov-12 4:28 
GeneralRe: Shred a folder Pin
MehdiHazrati27-Nov-12 4:50
MemberMehdiHazrati27-Nov-12 4:50 
GeneralRe: Shred a folder Pin
Richard MacCutchan27-Nov-12 5:05
mveRichard MacCutchan27-Nov-12 5:05 
GeneralRe: Shred a folder Pin
MehdiHazrati27-Nov-12 5:23
MemberMehdiHazrati27-Nov-12 5:23 
QuestionRe: Shred a folder Pin
David Crow27-Nov-12 6:04
MemberDavid Crow27-Nov-12 6:04 
GeneralRe: Shred a folder Pin
Richard MacCutchan27-Nov-12 6:29
mveRichard MacCutchan27-Nov-12 6:29 
QuestionRe: Shred a folder Pin
David Crow27-Nov-12 6:03
MemberDavid Crow27-Nov-12 6:03 
AnswerRe: Shred a folder Pin
jschell27-Nov-12 13:08
Memberjschell27-Nov-12 13:08 
GeneralRe: Shred a folder Pin
MehdiHazrati27-Nov-12 17:45
MemberMehdiHazrati27-Nov-12 17:45 
GeneralRe: Shred a folder Pin
jschell28-Nov-12 8:33
Memberjschell28-Nov-12 8:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.