Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi, I have tried some code ejecting CD ROM drive and one of the functions is CreateFile, the first argument of it is filename. At first I passed in "F:" (my cd rom drive letter) only, and there was an error with error code of 21 (device is not ready), I rechecked the sample code and I should've passed in @"\\.\F:" so what is the string "\\.\F:"?

Your help would be highly appreciated! Thanks!
Posted
Comments
[no name] 17-Sep-12 11:52am    
"@"\\.\F:"... there is the clue. The \\. is a UNC path to the local machine and does not make any sense. \F: is the path to the F drive. So @"\\.\F:" is the same thing as @"\F:"
Maciej Los 17-Sep-12 12:43pm    
My virtual 5!
supernorb 17-Sep-12 13:05pm    
I don't know what UNC path is, but "\\.\F:" does really make sense in my case, the CreateFile function can be executed successfully with it passed in as the first argument (filename) but not with "F:" (which is the most meaningful ???) passed in!
I don't think they are the same, of course at least to the way CreateFile works!
[no name] 17-Sep-12 13:14pm    
It actually means exactly what I told you it means. The reason that you have to put the UNC path in the string is clearly identified in the documentation, "to call the Unicode version ...". All strings are natively unicode in .NET

I'm not sure you can use CreateFile to write to a CD-ROM (people are still using those?). But "\\.\F:" doesn't make sense. "\\." would be the root of the current drive, probably "C:\", and "F:" would point to your F drive, but putting them together doesn't work (you'd be going to C:\F:\, which is invalid).

Not to mention the first "\" is escaped, and the second is not, so depending on whether the string is using an @ or not (i.e. @"\\.\F:") you could also be going to C:\\F: (a nameless directory, not allowed by Windows to my knowledge, then a drive inside that which is invalid), or the F is a control character (form feed I think?) which should be invalid in Windows paths as well.

So to summarize, it doesn't mean anything.

On the other hand, your error is probably popping up because you use CreateFile, and then give it a path to a drive. You need to give it a path to a file, e.g. "F:\\myfile.ext".
 
Share this answer
 
Comments
[no name] 17-Sep-12 11:50am    
Could also mean a UNC path. But a UNC path to the local machine does not make much sense either.
lewax00 17-Sep-12 11:56am    
Yeah the command line spit an error about that when I tried to use it as a path, I'm not sure what a UNC path is but I did get that Windows didn't like it...and now I'm off to Google to learn. (Edit: never mind, I've used those before, just didn't know the name...)
[no name] 17-Sep-12 12:18pm    
Lol... well good that you were at least willing to look it up instead of posting it as a QA question... :-)
lewax00 17-Sep-12 12:22pm    
But if I use Google instead, how will I ever become a platinum enquirer?! :P
[no name] 17-Sep-12 12:24pm    
Would not bother me a bit if I never ever got platinum for that one. In fact, I am rather surprised that I have platinum at all in anything.
CreateFile has many uses beyond creating and opening files. Passing a string such as "\\.\F:" opens a logical drive so that DeviceIO functions can be used.

See http://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85).aspx[^]

Alan.
 
Share this answer
 
Comments
supernorb 17-Sep-12 13:01pm    
Yeah, you are right, but could you please be more elaborated on the meaning of "\\.\F:", I really don't understand what it is? (Of course the "F:" is my CD drive, but what about the prefix???)!
Thank you so much, you deserve my click on the accept solution button!
lewax00 17-Sep-12 13:28pm    
From the page he linked to: "When opening a volume or removable media drive (for example, a floppy disk drive or flash memory thumb drive), the lpFileName string should be the following form: "\\.\X:". Do not use a trailing backslash (\), which indicates the root directory of a drive."

There's your answer, it's just used to tell the function you're opening a drive. It has no meaning on its own, just in the context of the function.
supernorb 18-Sep-12 9:58am    
Yeah, thanks, I thought it can be used somewhere else

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900