Click here to Skip to main content
15,884,472 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionSetupDiGetDeviceRegistryProperty - buffer size? Pin
Vaclav_27-Nov-12 6:39
Vaclav_27-Nov-12 6:39 
AnswerRe: SetupDiGetDeviceRegistryProperty - buffer size? Pin
Richard MacCutchan27-Nov-12 6:50
mveRichard MacCutchan27-Nov-12 6:50 
AnswerRe: SetupDiGetDeviceRegistryProperty - buffer size? Pin
Jochen Arndt27-Nov-12 22:54
professionalJochen Arndt27-Nov-12 22:54 
GeneralRe: SetupDiGetDeviceRegistryProperty - buffer size? Pin
Vaclav_28-Nov-12 4:50
Vaclav_28-Nov-12 4:50 
GeneralRe: SetupDiGetDeviceRegistryProperty - buffer size? Pin
Jochen Arndt28-Nov-12 5:35
professionalJochen Arndt28-Nov-12 5:35 
GeneralRe: SetupDiGetDeviceRegistryProperty - buffer size? Pin
Vaclav_28-Nov-12 7:03
Vaclav_28-Nov-12 7:03 
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
Vaclav_29-Nov-12 5:52 
Here is yet another attempt.I stopped using MFC error printout, but the error reporting is still same.

It appears that the function will always fail - returns 0 when
buffer = NULL;
buffersize = 0;

And when buffersize returned is 0 the last error is always ERROR_INVALID_DATA.
When buffersize != 0 and I double it - in next function call I still get ERROR_INVALID_DATA.

I must be using the function incorrectly, but I did follow the sample code.

BTW - setting the buffer size initially > 0 gives same results - ERROR_INVALID_DATA
And I do use "code" when I copy my code here.

I am basically stuck and I AM using this enumeration to learn how to output to USB device. I like to learn how to use the API's, the "wrapper" samples ( copy and play) in CodeProject do not interest me, but I'll take another look at them.

Thanks for all your help.
Cheers Vaclav


// display list of all (installed) hardware devices
bool C_USB::C_DeviceList()
{
TRACE("\nbool C_USB::C_DeviceList()");
TRACE("\ndisplay list of all (installed) hardware devices");

TRACE("\nEnumerator test ");
HDEVINFO hDevInfo;
SP_DEVINFO_DATA DeviceInfoData;
DWORD i;


HDEVINFO DeviceInfoSet = SetupDiGetClassDevs(
NULL,
"USB", //NULL,
NULL,
DIGCF_ALLCLASSES | DIGCF_PRESENT);
TRACE("\nSetupDiGetClassDevs.. USB devices ");

// Create a HDEVINFO with all present devices.
hDevInfo = SetupDiGetClassDevs(NULL,
0, // Enumerator
0,
DIGCF_PRESENT | DIGCF_ALLCLASSES );

if (hDevInfo == INVALID_HANDLE_VALUE)
{
// Insert error handling here.
return 1;
}

// Enumerate through all devices in Set.

DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
for (i=0;SetupDiEnumDeviceInfo(hDevInfo,i,
&DeviceInfoData);i++)
{
DWORD DataT;
//LPTSTR buffer; // = NULL;
LPTSTR buffer = NULL;
DWORD buffersize = 0;
DWORD Property = SPDRP_DEVICEDESC; // SPDRP_FRIENDLYNAME;
bool bResult;

//buffersize = 2048;
//Property = SPDRP_FRIENDLYNAME;
for (Property = SPDRP_DEVICEDESC /* SPDRP_FRIENDLYNAME*/ ; Property != SPDRP_MAXIMUM_PROPERTY; Property++)
{
buffer = NULL;
buffersize = 0;

bResult = SetupDiGetDeviceRegistryProperty(
hDevInfo,
&DeviceInfoData,
Property,
&DataT,
(PBYTE)buffer,
buffersize,
&buffersize);
LONG lError = GetLastError();
TRACE("\nProperty %i ", Property);
switch(lError)
{
case ERROR_INSUFFICIENT_BUFFER :
{
TRACE("\nResize buffer ");
buffersize *=2;
bResult = SetupDiGetDeviceRegistryProperty(
hDevInfo,
&DeviceInfoData,
Property,
&DataT,
(PBYTE)buffer,
buffersize,
&buffersize);
LONG lError = GetLastError();
switch(lError)
{
case ERROR_INVALID_DATA:
{
TRACE("\nERROR_INVALID_DATA");
break;
}
default:
{
TRACE("\nResize buffer ");
break;
}
}
break;
}
case ERROR_INVALID_DATA:
{
TRACE("\n ERROR_INVALID_DATA");
break;
}
default:
TRACE("\nUnknown ");
}
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
Vaclav_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
Vaclav_30-Nov-12 2:43 
AnswerRe: SetupDiGetDeviceRegistryProperty - buffer size? Pin
Cristian Amarie3-Dec-12 8:58
Cristian Amarie3-Dec-12 8:58 
GeneralRe: SetupDiGetDeviceRegistryProperty - buffer size? Pin
Vaclav_3-Dec-12 12:39
Vaclav_3-Dec-12 12:39 
GeneralRe: SetupDiGetDeviceRegistryProperty - buffer size? Pin
Cristian Amarie3-Dec-12 17:37
Cristian Amarie3-Dec-12 17:37 
GeneralRe: SetupDiGetDeviceRegistryProperty - buffer size? Pin
Cristian Amarie3-Dec-12 18:52
Cristian Amarie3-Dec-12 18:52 
GeneralRe: SetupDiGetDeviceRegistryProperty - buffer size? Pin
Vaclav_4-Dec-12 5:58
Vaclav_4-Dec-12 5:58 
GeneralRe: SetupDiGetDeviceRegistryProperty - buffer size? Pin
Cristian Amarie4-Dec-12 7:11
Cristian Amarie4-Dec-12 7:11 
QuestionShred a folder Pin
MehdiHazrati26-Nov-12 20:52
MehdiHazrati26-Nov-12 20:52 
QuestionRe: Shred a folder Pin
David Crow27-Nov-12 3:57
David Crow27-Nov-12 3:57 
AnswerRe: Shred a folder Pin
MehdiHazrati27-Nov-12 4:26
MehdiHazrati27-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
MehdiHazrati27-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
MehdiHazrati27-Nov-12 5:23 

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.