Parameters for CreateFile (Driver Development)

Status
Not open for further replies.

Zhou He

Level 1
Thread author
Mar 13, 2017
7
29
32
China
I'm trying to write IOCTL example based on samples from Microsoft's Github repo: Windows-driver-samples/testapp.c at master · Microsoft/Windows-driver-samples · GitHub

The sample is relatively easy but while creating user mode application they use "CREATE_ALWAYS" flag for CreateFile function.
create.png


Other samples from different sources use "OPEN_EXISTING" flag:
Open.png

and as MSDN says: "For devices other than files, this parameter is usually set to OPEN_EXISTING."


I think the second approach is more intuitive than the first one, but both works for me.

We just trying to open device not create, why they use "CREATE_ALWAYS" flag?
I don't know, maybe I'm wrong, just confused.

P.S. They check if last error is "ERROR_FILE_NOT_FOUND", it this possible to get this error when using "CREATE_ALWAYS"? I don't think so, but it's possible when using "OPEN_EXISTING".
 
Last edited:
  • Like
Reactions: XhenEd
Status
Not open for further replies.