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, Augustexpected primary-expression before ')' token
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, Augustexpected 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
"Think not but that I know these things; or think
I know them not: not therefore am I short
Of knowing what I ought."
-John Milton, Paradise Regained (1671)
"Work hard and it might happen."
-XSquared
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:expected primary-expression before ')' token
http://msdn.microsoft.com/library/en...asp?frame=true
And I did it the way they said.
Thanks.
Last edited by Queatrix; 04-20-2005 at 05:48 PM.
Even after trying this:
It comes up with this:Code:WriteFile("doucument1.txt","Data",0,NULL,NULL);
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)
"Think not but that I know these things; or think
I know them not: not therefore am I short
Of knowing what I ought."
-John Milton, Paradise Regained (1671)
"Work hard and it might happen."
-XSquared
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.
Last edited by Ken Fitlike; 04-20-2005 at 07:51 PM.
CProgramming FAQ
Caution: this person may be a carrier of the misinformation virus.
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?
"Think not but that I know these things; or think
I know them not: not therefore am I short
Of knowing what I ought."
-John Milton, Paradise Regained (1671)
"Work hard and it might happen."
-XSquared
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);
Last edited by Quantum1024; 04-20-2005 at 10:57 PM.
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...
"Think not but that I know these things; or think
I know them not: not therefore am I short
Of knowing what I ought."
-John Milton, Paradise Regained (1671)
"Work hard and it might happen."
-XSquared