小编The*_*gue的帖子

Writefile导致崩溃,访问冲突

所以基本上我希望将一个字节数组写入文件,但程序崩溃了.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);
Run Code Online (Sandbox Code Playgroud)

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

c++ file-io access-violation

9
推荐指数
1
解决办法
2861
查看次数

标签 统计

access-violation ×1

c++ ×1

file-io ×1