Why doesn't my compiler like this?
This is the error that comes up:Code:WriteFile("doucument1.txt","Data",0,NULL,OVERLAPPED);
Thanks in advance, AugustQuote:
expected primary-expression before ')' token
Printable View
Why doesn't my compiler like this?
This is the error that comes up:Code:WriteFile("doucument1.txt","Data",0,NULL,OVERLAPPED);
Thanks in advance, AugustQuote:
expected primary-expression before ')' token
Probably because OVERLAPPED is the name of the structure. If you didn't open the file with FILE_FLAG_OVERLAPPED, change the last parameter to NULL.
Edit: Source, msdn
Why doesn't my compiler like this?
This is the error that comes up:Code:WriteFile("doucument1.txt","Data",0,NULL,OVERLAPPED);
Why does it do this, I looked it up here:Quote:
expected primary-expression before ')' token
http://msdn.microsoft.com/library/en...asp?frame=true
And I did it the way they said.
Thanks.
Even after trying this:
It comes up with this:Code:WriteFile("doucument1.txt","Data",0,NULL,NULL);
Quote:
invalid conversion from `const void*' to `void*'
initializing argument 1 of `BOOL WriteFile(void*, const void*, DWORD, DWORD*, _OVERLAPPED*)'
My bad. Your first argument should be a handle returned by CreateFile (take a look at msdn for info on that function)
The basic steps in using winapi file io are:
- Obtain a file handle with CreateFile.
- Use that file handle to perform write operations (WriteFile) or read operations (ReadFile).
- Free the file handle when you're done with CloseHandle.
There is an example on this msdn page which should hopefully set you straight on this.
Edit: Thanks mods for merging invidious cross-post into single thread; much appreciated. :)
When I use those the compiler doesn't catch an error or a warning, but when the program is executed a "Program Error" MessageBox comes up. Why is it doing that? I am using Dev-C++.
We're not mind readers...Where's your code? :rolleyes:
here is an example of using WriteFile
Code:HANDLE hFile=CreateFile("file.txt", GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
DWORD dwBytes;
if (hFile!=INVALID_HANDLE_VALUE)
{
WriteFile(hFile, "Data", 4, &dwBytes, NULL);
CloseHandle(hFile);
}
else
MessageBox(NULL, "Error opening file", NULL, MB_ICONERROR);
Hey! That works! Thanks, I think I understand it now, I was doing it wrong before. Just one question, would you know how to make breaks? "\n" doesn't work. Thanks.
You might have to use "\r\n" if I recall correctly...
Wow. It worked. Thanks.