我有一个编写为 Windows 桌面应用程序的代码。我想将其转换为 windows storeapp。但是,我找不到 SafeFileHandle 的等价物。
这是代码。
using Microsoft.Win32.Safehandles;
using System;
using System.IO;
using System.Runtime.InteropServices;
internal sealed class FileIO
{
internal const int FILE_ATTRIBUTE_NORMAL = 0x80;
internal const int FILE_FLAG_DELETE_ON_CLOSE = 0x4000000;
internal const int FILE_FLAG_OVERLAPPED = 0x40000000;
internal const int FILE_FLAG_SEQUENTIAL_SCAN = 0x8000000;
internal const int FILE_SHARE_DELETE = 4;
internal const int FILE_SHARE_READ = 1;
internal const int FILE_SHARE_WRITE = 2;
internal const uint GENERIC_READ = 0x80000000;
internal const uint GENERIC_WRITE = 0x40000000;
internal const int INVALID_HANDLE_VALUE = -1;
internal const int OPEN_ALWAYS = 4;
internal const int OPEN_EXISTING = 3;
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern SafeFileHandle CreateFile(string lpFileName, uint dwDesiredAccess, int dwShareMode, IntPtr lpSecurityAttributes, int dwCreationDisposition, int dwFlagsAndAttributes, int hTemplateFile);
}
Windows Storeapp 不支持 Microsoft.Win32.Safehandles dll。它给出错误“名称空间'Microsoft'中不存在类型或名称空间名称Win32(缺少程序集引用?)”
因此,SafeFilehandle 会给出类似“找不到类型或命名空间名称‘SafeFileHandle’”的错误。
你有什么建议吗?
谢谢。