dargueta I'm struggling to get the program to write the sector back to the disk once it has found the correct amount of slack. I'm not too familiar with C++ but when i'm using WriteFile with the same parameters as the ReadFile operation (which is working) before it's failing to write and going into the "Cannot write slack" loop. Can you spot anything immediate?
Code:dwBytesRead = 0; if(!WriteFile(hDrive, memsectptr, clustersize, &dwBytesRead, NULL)) { printf("Error writing to slack\n"); return 0; } //WriteFile(hDrive, memsectptr, clustersize, &dwBytesRead, NULL); printf("Operation Successful\n"); printf("Stored in logical sector: %d\n", clustercount); printf("Slacksize = %d\n", slacksize); filesize = 0;
EDIT: Try using this function in your error catching code. Requires windows.h.
If you're using this on the C: drive it won't work. Windows will block you.Code:void printWinError(void) { DWORD dwError = GetLastError(); char *pszMessage = NULL; FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM, /*options*/ NULL, /*message source, don't need for our purposes here*/ dwError, /*error code whose corresponding message we want*/ 0, /*use default language*/ (LPVOID)&pszMessage, /*pointer to the buffer receiving the message*/ 1, /*minimum number of bytes to allocate*/ NULL); /*extra arguments*/ printf("ERROR %08X: %s\n",dwError,pszMessage); LocalFree(pszMessage); }
I've added this code into the stdafx.h header file but i'm getting the following error message on compile:
error C2664: 'FormatMessageW' : cannot convert parameter 5 from 'LPVOID' to 'LPWSTR'
1> Conversion from 'void*' to pointer to non-'void' requires an explicit cast
Oooh, my bad. Replace the typecast LPVOID with LPWSTR and change pszMessage from char to wchar_t. Also, capitalize the s in printf.
It should now look like this:
Code:void printWinError(void) { DWORD dwError = GetLastError(); wchar_t *pszMessage = NULL; FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM, /*options*/ NULL, /*message source, don't need for our purposes here*/ dwError, /*error code whose corresponding message we want*/ 0, /*use default language*/ (LPWSTR)&pszMessage, /*pointer to the buffer receiving the message*/ 1, /*minimum number of bytes to allocate*/ NULL); /*extra arguments*/ printf("ERROR %08X: %S\n",dwError,pszMessage); LocalFree(pszMessage); }
Cheers,
Found out the problem I was having was because I hadn't opened the disk in read/write mode, only read (numpty)
Yeah, that'll do it.![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks