title: Error code 122 using SetupDiGetDeviceRegistryPropertyW to get the required size
body: <p>I want to get the Device ID of a USB stick by using the Setup API, but first I am trying to understand some of the functions I have to use. The <code>SetupDiGetDeviceRegistryProperty</code> documentation says I can send NULL to the buffer and buffer size to get the required size, but I am getting the <code>122</code> error code, which means: </p>
  
  <blockquote>
    <p>The data area passed to a system call is too small</p>
  </blockquote>
  
  <p>Can anyone tell me what am I doing wrong?</p>
  
  <p>Here is my code so far:</p>
  
  <pre><code>#include &lt;Windows.h&gt;
  #include &lt;wchar.h&gt;
  #include &lt;SetupAPI.h&gt;
  
  #pragma comment(lib, "Setupapi.lib")
  
  int wmain(int argc, wchar_t *arv[])
  {
      // SetupDiGetClassDevs
      HDEVINFO hDeviceInfo;
      DWORD filterDevInfo = DIGCF_ALLCLASSES;
  
      hDeviceInfo = SetupDiGetClassDevsW(NULL, NULL, NULL, filterDevInfo);
  
      if (hDeviceInfo != INVALID_HANDLE_VALUE)
      {
          // SetupDiEnumDeviceInfo
          DWORD memberIndex = 0;
          SP_DEVINFO_DATA devInfoData;
  
          devInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
  
          if (!SetupDiEnumDeviceInfo(
              hDeviceInfo,
              memberIndex,
              &amp;devInfoData))
          {
              fwprintf(stderr, L"Error on enum: %u\n", GetLastError());
              return 1;
  
          }
  
          // SetupDiGetDeviceRegistryProperty
          DWORD propertyRetrieved = SPDRP_DEVICEDESC;
          DWORD requiredSize;
  
          // First call to get the required size for the buffer
  
          if (!SetupDiGetDeviceRegistryPropertyW(
              hDeviceInfo,
              &amp;devInfoData,
              propertyRetrieved,
              NULL,
              NULL,
              0,
              &amp;requiredSize))
          {
              fwprintf(stderr, L"Error on registry property: %u\n", GetLastError());
              return 1;
  
          }
  
      }
      else
      {
          wprintf(L"Error code: %u\n", GetLastError());
          return 1;
      }
  
      return 0;
  }
  </code></pre>