Click here to Skip to main content
15,867,834 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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 
GeneralRe: SetupDiGetDeviceRegistryProperty - buffer size? Pin
Jochen Arndt29-Nov-12 6:49
professionalJochen Arndt29-Nov-12 6:49 
As already noted, there must be something else wrong when you get other error codes.

This is extracted from existing working code to enumerate serial ports (note also how it looks compared to your posts):
C++
#include <WinIoCtl.h> // Pre-defined GUIDs

DWORD nNumDev = 0;
SP_DEVINFO_DATA	DevInfoData;
::ZeroMemory(&DevInfoData, sizeof(SP_DEVINFO_DATA));
DevInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
HDEVINFO hDevInfo = ::SetupDiGetClassDevs(&GUID_DEVINTERFACE_COMPORT, 
    NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); 
BOOL bResult = (INVALID_HANDLE_VALUE != hDevInfo);
while (bResult)
{
    bResult = ::SetupDiEnumDeviceInfo(hDevInfo, nNumDev++, &DevInfoData);
    if (!bResult)
    {
        if (ERROR_NO_MORE_ITEMS == ::GetLastError())
            bResult = TRUE;
        break;
    }
    DWORD dwDataType = 0;
    DWORD dwReqSize = 0;
    BYTE lpszBuf[1024]; // 511 Unicode chars is sufficient
    bResult = ::SetupDiGetDeviceRegistryProperty(
        hDevInfo, &DevInfoData, SPDRP_FRIENDLYNAME, &dwDataType,
        lpszBuf, sizeof(lpszBuf), &dwReqSize);
    // Show/copy lpszBuf casted to LPCTSTR here upon success
}
if (!bResult)
{
    // Pass hRes to FormatMessage() to retrieve the error message
    HRESULT hRes = HRESULT_FROM_SETUPAPI(::GetLastError());
}

Please note this cite from the Guidelines link I have posted:
Quote:
If a SetupAPI function returns successfully, your code must not call GetLastError.

That means that the error condition has to be checked by return values, and not by the value returned by GetLastError()!
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 
QuestionRe: Shred a folder Pin
David Crow27-Nov-12 6:04
David Crow27-Nov-12 6:04 

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.