CreateFile、FILE_FLAG_BACKUP_SEMANTICS、目录管理和句柄
CreateFile, FILE_FLAG_BACKUP_SEMANTICS, Directory Management and Handles
我正试图获取一个目录句柄,以便检索目录的标识符。文档(链接到上面)指定FILE_FLAG_BACKUP_SEMANTICS
标志需要传递给CreateFile
函数,以便检索句柄本身。
然而,在查阅pinvoke的kernel32.dll
签名时,大多数C#候选看起来如下:
[DllImport("kernell32.dll", SetLastError = true)]
public static extern SafeFileHandle CreateFile(
string lpFileName,
[MarshalAs(UnmanagedType.U4)] FileAccess dwDesiredAccess,
[MarshalAs(UnmanagedType.U4)] FileShare dwShareMode,
IntPtr securityAttributes,
[MarshalAs(UnmanagedType.U4)] FileMode dwCreationDisposition,
[MarshalAs(UnmanagedType.U4)] FileAttributes dwFlagsAndAttributes,
IntPtr hTemplateFile
);
上述一对一参数映射到C++CreateFile意味着dwFlagsAndAttributes
参数是FILE_FLAG_BACKUP_SEMANTICS
的占位符;但是,FileAttribute
枚举似乎与该标志不匹配。
现在(它坏了)我的电话看起来像:
var createdFolder =
FileSystemInteractor.CreateFile(
fullPathWithFolderName,
FileAccess.Read,
FileShare.Read,
IntPtr.Zero,
FileMode.Open,
Kernel32.FILE_FLAG_BACKUP_SEMANTICS,
IntPtr.Zero
);
CCD_ 7显然包含了正确的标志。收到的编译器错误是:
无法从"uint"转换为"System.IO.FileAttributes"
这个错误是有道理的;我只是不确定我能做什么按摩签名,因为我是extern
函数的新手。
是否有对应于所需标志的FileAttributes
?我需要更改extern
签名吗?
在代码中包含此枚举定义:
[Flags]
private enum File_Attributes : uint
{
Readonly = 0x00000001,
Hidden = 0x00000002,
System = 0x00000004,
Directory = 0x00000010,
Archive = 0x00000020,
Device = 0x00000040,
Normal = 0x00000080,
Temporary = 0x00000100,
SparseFile = 0x00000200,
ReparsePoint = 0x00000400,
Compressed = 0x00000800,
Offline = 0x00001000,
NotContentIndexed = 0x00002000,
Encrypted = 0x00004000,
Write_Through = 0x80000000,
Overlapped = 0x40000000,
NoBuffering = 0x20000000,
RandomAccess = 0x10000000,
SequentialScan = 0x08000000,
DeleteOnClose = 0x04000000,
BackupSemantics = 0x02000000,
PosixSemantics = 0x01000000,
OpenReparsePoint = 0x00200000,
OpenNoRecall = 0x00100000,
FirstPipeInstance = 0x00080000
}
System.IO中定义的文件属性不包括许多属性。
相关文章:
- 外壳包装器句柄/执行交互式命令管道C++ UNIX
- 如何获取边缘窗口句柄 (HWND)?
- 枚举进程模块在有效句柄上返回无效句柄
- 在 c/c++ 中打开 PhysicalDrive 的句柄并写入 MBR 的 linux 等效是什么?
- 从运行服务的应用程序代码中提取窗口句柄
- 在读取文件后重置句柄
- 是否有像地图这样的C++结构,但我得到的不是值的键,而是值的句柄?
- Microsoft ODBC 无法创建有效的句柄
- 我是否可以使用 win32 句柄以编程方式记录发送到/接收到 USB/COM 的内容
- 获取特定进程的句柄数
- C++ 创建 NdisProt 驱动程序的句柄
- 是否需要关闭来自 WinHTTP 异步的句柄?
- Windows HANDLE RAII 管理,如果返回布尔值而不是句柄怎么办?
- CreateFile、FILE_FLAG_BACKUP_SEMANTICS、目录管理和句柄
- 检索 Windows 资源管理器的地址栏编辑控件的句柄
- 如何正确地管理句柄
- 不存储函数返回句柄时的内存管理
- 如何检查Win32中使用c++的窗口句柄是否在管理模式下运行
- 是否有可能由windows管理的2个窗口具有相同的窗口句柄值?
- 在c++中有效地管理数组二进制堆句柄