Click here to Skip to main content
15,790,645 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: SetupDiGetDeviceRegistryProperty - buffer size? Pin
Jochen Arndt28-Nov-12 9:19
professionalJochen Arndt28-Nov-12 9:19 
GeneralRe: SetupDiGetDeviceRegistryProperty - buffer size? Pin
Vaclav_29-Nov-12 6:52
Vaclav_29-Nov-12 6:52 
GeneralRe: SetupDiGetDeviceRegistryProperty - buffer size? Pin
Jochen Arndt29-Nov-12 7:49
professionalJochen Arndt29-Nov-12 7:49 
GeneralRe: SetupDiGetDeviceRegistryProperty - buffer size? Pin
Vaclav_29-Nov-12 9:23
Vaclav_29-Nov-12 9:23 
GeneralRe: SetupDiGetDeviceRegistryProperty - buffer size? Pin
Jochen Arndt29-Nov-12 22:16
professionalJochen Arndt29-Nov-12 22:16 
GeneralRe: SetupDiGetDeviceRegistryProperty - buffer size? Pin
Vaclav_30-Nov-12 3:43
Vaclav_30-Nov-12 3:43 
AnswerRe: SetupDiGetDeviceRegistryProperty - buffer size? Pin
Cristian Amarie3-Dec-12 9:58
Cristian Amarie3-Dec-12 9:58 
GeneralRe: SetupDiGetDeviceRegistryProperty - buffer size? Pin
Vaclav_3-Dec-12 13:39
Vaclav_3-Dec-12 13: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 18:37
Cristian Amarie3-Dec-12 18:37 
GeneralRe: SetupDiGetDeviceRegistryProperty - buffer size? Pin
Cristian Amarie3-Dec-12 19:52
Cristian Amarie3-Dec-12 19:52 
GeneralRe: SetupDiGetDeviceRegistryProperty - buffer size? Pin
Vaclav_4-Dec-12 6:58
Vaclav_4-Dec-12 6:58 
GeneralRe: SetupDiGetDeviceRegistryProperty - buffer size? Pin
Cristian Amarie4-Dec-12 8:11
Cristian Amarie4-Dec-12 8:11 
QuestionShred a folder Pin
MehdiHazrati26-Nov-12 21:52
MehdiHazrati26-Nov-12 21:52 
QuestionRe: Shred a folder Pin
David Crow27-Nov-12 4:57
David Crow27-Nov-12 4:57 
AnswerRe: Shred a folder Pin
MehdiHazrati27-Nov-12 5:26
MehdiHazrati27-Nov-12 5:26 
GeneralRe: Shred a folder Pin
Richard MacCutchan27-Nov-12 5:28
mveRichard MacCutchan27-Nov-12 5:28 
GeneralRe: Shred a folder Pin
MehdiHazrati27-Nov-12 5:50
MehdiHazrati27-Nov-12 5:50 
GeneralRe: Shred a folder Pin
Richard MacCutchan27-Nov-12 6:05
mveRichard MacCutchan27-Nov-12 6:05 
GeneralRe: Shred a folder Pin
MehdiHazrati27-Nov-12 6:23
MehdiHazrati27-Nov-12 6:23 
QuestionRe: Shred a folder Pin
David Crow27-Nov-12 7:04
David Crow27-Nov-12 7:04 
GeneralRe: Shred a folder Pin
Richard MacCutchan27-Nov-12 7:29
mveRichard MacCutchan27-Nov-12 7:29 
QuestionRe: Shred a folder Pin
David Crow27-Nov-12 7:03
David Crow27-Nov-12 7:03 
AnswerRe: Shred a folder Pin
jschell27-Nov-12 14:08
jschell27-Nov-12 14:08 
GeneralRe: Shred a folder Pin
MehdiHazrati27-Nov-12 18:45
MehdiHazrati27-Nov-12 18:45 
GeneralRe: Shred a folder Pin
jschell28-Nov-12 9:33
jschell28-Nov-12 9: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.