problem about writefile-Collection of common programming errors


  • ThePlague
    c++ access-violation writefile
    So basically I wish to write a byte array to a file, however the program crashes. Unhandled exception at 0x7766DEE1 (KernelBase.dll) in append.exe: 0xC0000005: Access violation writing location 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 *)

  • Yakov
    c++ windows writefile freopen
    I have wrote the following code:int fd = _dup(fileno(stdout)); FILE* tmp = freopen(“tmp”,”w+”,stdout); HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE); if (out == INVALID_HANDLE_VALUE){//error } else if (out == NULL) {//error } else {WriteFile(out, “num”, sizeof(“num”), NULL, NULL);}In the last line I get an assertion “Unhandled exception…:Access violation writing location 0x000000” What could be a problem and the fix for it?Thank you.P.S:Due to limitation of the project I can`t use freopen