views:

30

answers:

1

Hello,

I would like to know whether it is possible to call a CreateFile Function in Visual C++ to create a file with attribute FILE_ATTRIBUTE_DEVICE (0x00000040 hex, 64 decimal). According to the MSDN API, FILE_ATTRIBUTE_DEVICE is reserved and therefore I cannot use it, but I know there must be some way to create a file with such attributes. What must I do to do this? Are there other API calls, or do I need to make a new struct?

Thanks

+1  A: 

The flag exists to identify handles that represent devices rather than files. For example, using CreateFile to open \\.\C: returns a handle to the drive device, rather than a file or directory handle.

You cannot create a new 'file' with this flag, since a file is not a device. Inventing/creating (rather than opening) a file handle with this flag requires writing a device driver to provide one (specifically, you create a name for your device object that a user-mode client can pass to CreateFile - the kernel creates the file handle and sets the FILE_ATTRIBUTE_DEVICE flag).

The CreateFile page and the Remarks section of the DeviceIOControl page should clarify things a bit further.

Zooba