Windows WriteFileGather 函数将最后一个错误设置为 ERROR_INVALID_PARAMETER

Windows WriteFileGather function set last error as ERROR_INVALID_PARAMETER

重现我的问题的示例代码:

#include <windows.h>
#include <iostream>

int main()
{
  using namespace std;
  HANDLE hdl = CreateFile("test.file", GENERIC_WRITE,
                          FILE_SHARE_WRITE, NULL, OPEN_ALWAYS,
                          FILE_ATTRIBUTE_NORMAL  |
                          FILE_FLAG_NO_BUFFERING |
                          FILE_FLAG_OVERLAPPED,
                          NULL);
  char data[4096] = {0};
  DWORD written = 0;

  for(size_t i = 0; i < sizeof(data); ++i)
    data[i] = 'a' + (i % 26);

  OVERLAPPED async_hdl = {0};
  FILE_SEGMENT_ELEMENT segs[3] = {0};

  segs[0].Buffer = PtrToPtr64(data);
  segs[1].Buffer = PtrToPtr64(data);

  if(!WriteFileGather(hdl, segs, 8192, NULL, &async_hdl)) {
    cout << "Last error: " << GetLastError() << endl;
    cout << "overlapped internal status: " << async_hdl.Internal << endl;
    // Last error: 87
    // overlapped internal status: 259
  }
  CloseHandle(hdl);
  return 0;
}

我用 Visual Studio 2012 编译它并在 Windows 7 上测试。作为内联注释,WriteFileGather 函数总是将最后一个错误设置为 ERROR_INVALID_PARAMETER (87) OVERLAPPED 结构的 Internal 字段是 259

我错过了什么?

MSDN:aSegmentArray ...系统内存页面并且必须在系统内存页面大小边界上对齐。使用 _aligned_malloc() 而不是堆栈内存。