can anyone help me fix this i cant seem to get CreateFile to open anything it compiles allright but does nothing
Code:CreateFile("C:\\Documents and Settings\\wmorrish\\Desktop\\sd.txt",OPEN_EXISTING,
NULL,NULL,NULL,NULL,NULL);
Printable View
can anyone help me fix this i cant seem to get CreateFile to open anything it compiles allright but does nothing
Code:CreateFile("C:\\Documents and Settings\\wmorrish\\Desktop\\sd.txt",OPEN_EXISTING,
NULL,NULL,NULL,NULL,NULL);
If you call GetLastError() after that function call you can get the error information.
About CreateFile() :
Your OPEN_EXISTING param is not the correct 2nd param. Look it up on MSDN.
http://msdn.microsoft.com/library/de...createfile.asp
I tried using the MSDN example but it still wont open the file....
Code:#include <windows.h>
#include <stdio.h>
int main()
{
HANDLE hFile;
hFile = CreateFile(TEXT("myfile.txt"), // file to open
GENERIC_READ, // open for reading
FILE_SHARE_READ, // share for reading
NULL, // default security
OPEN_EXISTING, // existing file only
FILE_ATTRIBUTE_NORMAL, // normal file
NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
printf("Could not open file (error %d)\n", GetLastError());
return 0;
}
}
Does that file exist? So it gives you an actual error? what's the value of the error?
If it's error value is 2 then that means it cannot find the file. Make sure it exists in the correct path.
The code above should work fine.
it doesnt give any error the file just wont open :(
What is it you are trying to do? If it doesn't output the error then that means the file was successfully opened and you now have a handle to the file to do whatever you want with. So maybe you should just post what you want to do and then maybe I can help you some more.
i don't think most standard compilers support programmers with more than 4 red boxes
i just want to open the file like system("myfile");
"opening" the file with the code above, opens it to the program to read/write to...it doesnt make the file pop open...
is there any way to do that?
http://faq.cprogramming.com/cgi-bin/...&id=1043284392
Try some of the other windows functions listed at the end of this FAQ entry