views:

47

answers:

2

I am creating the file using Createfile function. The C program is working fine but I am unable to see the created file in the respective folder. Also "view hidden files" option is checked.

A: 

You can check if the function worked correctly by checking out the returned HANDLE value.

edit: A C program continues to function (incorrectly though) if a functions fails. It's therefore very important to check each and every returned HANDLE.

edit: The returned HANDLE should not be INVALID_HANDLE_VALUE. (But I can imagine that NULL isn't good either).

Laurens Ruijtenberg
`CreateFile` does not return a `HRESULT`.
Philipp
yes,function is working correct only.I have checked the returned values(0).
Pradeep
The functionality looks like:memset(message_file, 0x00, sizeof(cmdline));sprintf(message_file,"D:\\temp2\\a.txt");fd = CreateFile(message_file, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);if (fd == INVALID_HANDLE_VALUE){return 1;}After execution of above ,I checked the folder D:\temp2,no file exist in the same.
Pradeep
What is message_file?Please post the code in your question. you can edit it - and the code formatting options are far more powerful
Chris Becke
A: 

Two things to check for. Number one, did it actually succeed? From the docs:

Return Value
     If the function succeeds, the return value is an open handle to the specified file, device, named pipe, or mail slot.
     If the function fails, the return value is INVALID_HANDLE_VALUE. To get extended error information, call GetLastError.

Number two, are you looking in the right place. Frequently, people who run their code from within an IDE don't realise that their current working directory is not always what they think it is. You can system("cd"); or something similar to see what it actually is.

Or, you can use absolute pathnames to ensure the file is being created at the right place (for testing, that is - you should never use absolute paths for production code).

If neither of those two suggestions help, you should post the code that shows the particular problem. Preferably enough so that we don't have to come back and ask for more.

paxdiablo