views:

14

answers:

2

I try create file in visual studio c++.

But it now work, what is wrong?

CreateFile("1",            
                   GENERIC_READ | GENERIC_WRITE,
                   0,                    
                   NULL,                 
                   OPEN_EXISTING,        
                   FILE_FLAG_OVERLAPPED, 
                   NULL); 
A: 

If you try to create a file (not open it), you should not specify the OPEN_EXISTING flag. Instead, pass the CREATE_NEW constant:

CreateFile("1",            
                   GENERIC_READ | GENERIC_WRITE,
                   0,                    
                   NULL,                 
                   CREATE_NEW,        
                   FILE_FLAG_OVERLAPPED, 
                   NULL); 
dark_charlie
throw errors http://pastebin.com/7KD33ig2
asd
#include <windows.h> at the top of your CPP file. First you should learn how to program, then start messing with WinAPI.
dark_charlie
A: 

This code tries to open existing file: OPEN_EXISTING. Replace it with CREATE_NEW to create new file.

Alex Farber