本文介绍了在 Visual Studio 中设置 FILE_ATTRIBUTE_DEVICE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以在 Visual C++ 中调用 CreateFile 函数来创建具有属性 FILE_ATTRIBUTE_DEVICE(0x00000040 十六进制,64 十进制)的文件.根据 MSDN API, FILE_ATTRIBUTE_DEVICE 是保留的,因此我不能使用它,但我知道必须有某种方法来创建具有此类属性的文件.我必须做什么才能做到这一点?是否有其他 API 调用,或者我需要创建一个新结构?

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?

谢谢

推荐答案

该标志的存在是为了标识代表设备而不是文件的句柄.例如,使用 CreateFile 打开 \\.\C: 返回驱动器设备的句柄,而不是文件或目录句柄.

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.

您不能使用此标志创建新的文件",因为文件不是设备.发明/创建(而不是打开)具有此标志的文件句柄需要编写一个设备驱动程序来提供一个(特别是,您为设备对象创建一个名称,用户模式客户端可以将其传递给 CreateFile - 内核创建文件句柄并设置 FILE_ATTRIBUTE_DEVICE 标志).

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).

CreateFile 页面和 DeviceIOControl 页面应该进一步澄清事情.

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

这篇关于在 Visual Studio 中设置 FILE_ATTRIBUTE_DEVICE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 15:55