Click here to Skip to main content
15,347,244 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: A class for operations with Large Integer Numbers Pin
Albert Holguin27-Nov-12 16:34
professionalAlbert Holguin27-Nov-12 16:34 
AnswerRe: A class for operations with Large Integer Numbers Pin
Stefan_Lang28-Nov-12 3:01
mveStefan_Lang28-Nov-12 3:01 
QuestionSetupDiGetDeviceRegistryProperty - buffer size? Pin
Vaclav_27-Nov-12 6:39
MemberVaclav_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
MemberVaclav_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
MemberVaclav_28-Nov-12 7:03 
Here is another try.
It is true that the sizing of the buffer will fail as poited out in the sample code which I copied / modified.
I have no problem getting readable messages using MFC code, but I made a mistake asking for the error message twice. Also got sidetracked by the error - I guess I was looking for something about buffer size.

All this aside - when I ask for buffer using SPDRP_DEVICEDESC it sort-off works,
but I did not looked up what exactly SPDRP_DEVICEDESC should contain. I am interested in friendly name for now.

But when I use SPDRP_FRIENDLYNAME , the sizing of buffer fails with "Data is invalid" and the buffer is still 0;

PS I copy my code into here with "code" selected and do preview and it looks formated to me. I have no clue if you guys do not see same format as me. SOrry.






// 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;
DWORD buffersize = 0;
DWORD Property = SPDRP_FRIENDLYNAME;

// SPDRP_DEVICEDESC;SPDRP_FRIENDLYNAME
// retrieve a REG_SZ string that contains the friendly name of a device.
//
// Call function with null to begin with,
// then use the returned buffer size (doubled)
// to Alloc the buffer. Keep calling until
// success or an unknown failure.
//
// Double the returned buffersize to correct
// for underlying legacy CM functions that
// return an incorrect buffersize value on
// DBCS/MBCS systems.
//
while (!SetupDiGetDeviceRegistryProperty(
hDevInfo,
&DeviceInfoData,
SPDRP_DEVICEDESC, //Property,
&DataT,
(PBYTE)buffer,
buffersize,
&buffersize))
{
{
TRACE("\nMFC Error dialog ");
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
0, // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
// Process any inserts in lpMsgBuf.
// ...
// Display the string.
// The data area passed to a system call is too
// small.
MessageBox( (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION );
// Free the buffer.
LocalFree( lpMsgBuf );

// Change the buffer size.
/*
if (buffer) LocalFree(buffer);
// Double the size to avoid problems on
// W2k MBCS systems per KB 888609.
buffer = LocalAlloc(LPTR,buffersize * 2);
*/
buffersize = buffersize*2;

// do it again with larger buffer

while (!SetupDiGetDeviceRegistryProperty(
hDevInfo,
&DeviceInfoData,
Property,
&DataT,
(PBYTE)buffer,
buffersize,
&buffersize))
{
{
TRACE("\nMFC Error dialog ");
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
0, // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
// Process any inserts in lpMsgBuf.
// ...
// Display the string.
// The data area passed to a system call is too
// small.
MessageBox( (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION );
// Free the buffer.
LocalFree( lpMsgBuf );

// Change the buffer size.
/*
if (buffer) LocalFree(buffer);
// Double the size to avoid problems on
// W2k MBCS systems per KB 888609.
buffer = LocalAlloc(LPTR,buffersize * 2);
*/
//buffersize = buffersize*2;
}

}


if (GetLastError() ==
ERROR_INSUFFICIENT_BUFFER)
{
// Change the buffer size.
if (buffer) LocalFree(buffer);
// Double the size to avoid problems on
// W2k MBCS systems per KB 888609.
// CCCC buffer = LocalAlloc(LPTR,buffersize * 2);
}
else
{
// Insert error handling here.
break;
}
}

printf("Result:[%s]\n",buffer);

if (buffer) LocalFree(buffer);
}


if ( GetLastError()!=NO_ERROR &&
GetLastError()!=ERROR_NO_MORE_ITEMS )
{
// Insert error handling here.
return 1;
}

// Cleanup
SetupDiDestroyDeviceInfoList(hDevInfo);
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 
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 

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.