title: Invalid handle when calling IOCTL_STORAGE_GET_MEDIA_SERIAL_NUMBER
body: <p>Anyone out there have experience of c/c++ IOCTL calls?
  Basically I'm trying to identify what port a USB memory stick is plugged into.
  I have all the USB info and have volume info. Apparantly to link these 2 blocks of info I need either the driver-key or serial-number.
  However when calling DeviceIoControl I'm getting invalid handle as the "last error code"</p>
  
  <p>My drive USB drive mounted to a directory in c:\ (not a drive letter) See below</p>
  
  <pre><code>//get a handle on the volume
  HANDLE hVolume;
  DWORD dwAccessFlags;
  
  dwAccessFlags = GENERIC_READ | GENERIC_WRITE;  
  
  hVolume = CreateFile(L"C:\_USB\MP1",
      dwAccessFlags,
      FILE_SHARE_READ | FILE_SHARE_WRITE,
      NULL,
      OPEN_EXISTING,
      0,
      NULL );
  if (hVolume == INVALID_HANDLE_VALUE) {
      printf("Invalid Handle");
  }
  
  //use the handle
  MEDIA_SERIAL_NUMBER_DATA* pserialNumberData = new MEDIA_SERIAL_NUMBER_DATA;
  wstring result;
  //HANDLE hVolume = OpenVolume(vname.substr(0, vname.length() - 1).c_str());
  DWORD   bytesReturned = 0;
  LPDWORD lpBytesReturned = &amp;bytesReturned;
  
  OVERLAPPED over;
  LPOVERLAPPED lpOver = &amp;over;
  BOOL success = 1;
  success = DeviceIoControl(
      (HANDLE) hVolume,                      // handle to device
       IOCTL_STORAGE_GET_MEDIA_SERIAL_NUMBER, // dwIoControlCode
       NULL,                                  // lpInBuffer
       0,                                     // nInBufferSize
      (LPVOID) pserialNumberData,                  // output buffer
      (DWORD) sizeof(MEDIA_SERIAL_NUMBER_DATA),                       // size of output buffer
      (LPDWORD) lpBytesReturned,             // number of bytes returned
      (LPOVERLAPPED) lpOver            // OVERLAPPED structure
      );
  wcout &lt;&lt; L"--&gt; GetSn() DeviceIoControl success " &lt;&lt; success &lt;&lt; endl;
  wcout &lt;&lt; L"--&gt; GetSn() DeviceIoControl Last error number " &lt;&lt; GetLastError() &lt;&lt; endl;
  wcout &lt;&lt; L"--&gt; GetSn() DeviceIoControl Bytes Returned " &lt;&lt; bytesReturned &lt;&lt; endl;
  wcout &lt;&lt; L"--&gt; GetSn() DeviceIoControl struct size " &lt;&lt; sizeof(MEDIA_SERIAL_NUMBER_DATA) &lt;&lt; endl;
  </code></pre>