How to call DeviceIoControl to retrieve the amount of memory it needs?

后端 未结 3 872
抹茶落季
抹茶落季 2021-01-27 17:09

I\'m trying to call DeviceIoControl(IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS) API, as shown here, but I need it to first \"tell me\" how much memory it needs (unlike th

3条回答
  •  星月不相逢
    2021-01-27 17:41

    You are getting error code ERROR_INVALID_PARAMETER when you have invalid parameter, like its name says. In your case it should be bad handle because all others looks fine, if we expect that dwIoControlCode argument is IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, lpInBuffer and nInBufferSize are ignored.

    In insufficient buffer you will get another error code mentioned in above comments.

    Lets check what is saying documentation:

    DeviceIoControl can accept a handle to a specific device. For example, to open a handle to the logical drive A: with CreateFile, specify \.\a:. Alternatively, you can use the names \.\PhysicalDrive0, \.\PhysicalDrive1, and so on, to open handles to the physical drives on a system.

    In other words, when you open handle with "C:\" instead of "\\.\c:" argument in CreateFile and use it in DeviceIoControl, the result is ERROR_INVALID_PARAMETER.

提交回复
热议问题