10

所以基本上我希望将一个字节数组写入文件,但是程序崩溃了。append.exe 中 0x7766DEE1 (KernelBase.dll) 处未处理的异常:0xC0000005:访问冲突写入位置 0x00000000。

BYTE *image ;
BYTE *bigMem;
#define REASONABLY_LARGE_BUFFER 16777216
file = CreateFile(fileName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

fileSize = GetFileSize(file, NULL);

bigMem = (BYTE *)HeapCreate(NULL, REASONABLY_LARGE_BUFFER, 0);
image = (BYTE *)HeapAlloc(bigMem, HEAP_ZERO_MEMORY, fileSize);
if (bigMem == NULL || image == NULL){
    printf("Allocation failed");
    return EXIT_FAILURE;
}
printf("We are writing to the file %p, with data location %p, and filesize %d\n", file, image, fileSize);
LPDWORD at = 0;
WriteFile(file, image, fileSize, at, NULL);

该打印件说:我们正在写入文件 00000038,数据位置为 02451590,文件大小为 161169

4

1 回答 1

18

如果重叠结构的参数为空,则传递给WriteFile用于存储写入的字节数 ( at)的参数只能为空。我建议更改为 a并传递一个指向它的指针。atDWORD

DWORD at;
WriteFile(file, image, fileSize, &at, NULL);
于 2013-06-16T05:57:12.850 回答