Writefile导致崩溃,并导致访问冲突
Writefile causes crash, with access violation
所以基本上我希望将字节数组写入文件,但是程序崩溃了。
附录.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 %dn", file, image, fileSize);
LPDWORD at = 0;
WriteFile(file, image, fileSize, at, NULL);
上面写着:我们写入文件00000038,数据位置为02451590,文件大小为161169
传递给WriteFile
用于存储写入字节数(at
)的参数只能为null,如果重叠结构的参数不是为null。我建议将at
改为DWORD
,并传递一个指针给它。
DWORD at;
WriteFile(file, image, fileSize, &at, NULL);
相关文章:
- 写入位置0x0000000C时发生访问冲突
- 引发异常:读取访问冲突**dynamicArray**为0x1118235.发生
- 链表中写入访问冲突的未知原因
- C++中的openCV Mat访问冲突
- C++尝试深度复制唯一指针时出现内存访问冲突
- C++ 中动态二维数组的访问冲突
- 从嵌套循环中的 std::list 中删除将返回访问冲突
- 使用向量的函数崩溃,调试器说访问冲突读取位置
- Windows C++程序中的访问冲突是否总是立即崩溃
- GetMonitorBrightness() 因访问冲突而崩溃
- 中止回复崩溃并出现访问冲突
- MEMCPY 后崩溃:访问冲突读取位置
- 创建对象时发生SSE访问冲突崩溃
- C++访问冲突崩溃
- Writefile导致崩溃,并导致访问冲突
- 在c++中对STL List使用push_back()会导致访问冲突,崩溃
- 访问计算机指针时发生访问冲突(c系统异常代码:c0000005),导致应用程序崩溃
- c++, WIN32, WndProc到成员函数崩溃(访问冲突0x88)
- 与JNI崩溃服务器JVM的访问冲突
- 通过WinAPI套接字连接到蓝牙设备时崩溃(读取位置0x00000004时发生访问冲突)