Note that there are some explanatory texts on larger screens.

plurals
  1. POWin 32 Writefile: Access Viloation and Error 1784
    text
    copied!<p>Two problems with the below code. To begin, I have been scouring this and various other forums for answers to my 1784 error code and everything I've tried has failed. Two of the threads I've checked on stackoverflow are <a href="https://stackoverflow.com/questions/6537416/writefile-returning-error-1784">WriteFile returning error 1784</a> and <a href="https://stackoverflow.com/questions/11287901/blockwrite-i-o-error-1784">BlockWrite I/O Error 1784</a>. I've checked some others on this forum but I'm not remembering exactly what the are right now.</p> <p>I'm trying to save an array of structs to an empty binary file. The first problem is that I get an access violation if my size variable (nNumberOfBytesToWrite parameter) is anything less about 99000 bytes. That number jumps around. For awhile when I was testing it would have the access violation if it was 99,999 bytes but not 100,000 bytes. Of course, what I eventually want to do is set the size to the size of the entire array. The original code to handle that is now commented out so I can test with various sizes.</p> <p>The second thing that happens (if I don't get an access violation) is I get error code 1784 and WriteFile fails every time. As other threads on this topic have stated, this is defined on MSDN as ERROR_INVALID_USER_BUFFER and the description is "The supplied user buffer is not valid for the requested operation." I've looked at MSDN's own example for opening files like this (<a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb540534%28v=vs.85%29.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/windows/desktop/bb540534%28v=vs.85%29.aspx</a>) and have tried some variations based on their code, but nothing seems to work.</p> <p>This problem is probably massively noob and I'm sure I'm overlooking something ridiculously simple, but if anyone has suggestions they'd be greatly appreciated.</p> <pre><code>case IDM_SAVE1: { HANDLE hFile = CreateFile("MineSave.mss", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); int test_buffer[] = {1,2,3,4,5,6,7,8,9,10}; if(hFile != INVALID_HANDLE_VALUE) { BOOL bSuccess; DWORD size = 100000; //DWORD size = (((sizeof(tile)) * tiles_total)); LPDWORD bytes_written = 0; bSuccess = WriteFile(hFile, test_buffer, size, bytes_written, NULL); if(bSuccess) { MessageBox(hwnd, "File saved successfully.", "Great Job!", MB_OK); } else { DWORD error = GetLastError(); MessageBox(hwnd, "Could not write to file.", "Error", MB_OK); } CloseHandle(hFile); } else { MessageBox(hwnd, "Could not create file.", "Error", MB_OK); } } break; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload