我有一个代码编写为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。 它给出了错误“Win32中不存在类型或命名空间名称 命名空间'Microsoft'(缺少程序集引用?)“
因此,SafeFilehandle会出现“无法找到类型或命名空间名称'SafeFileHandle'”的错误。
你有什么建议吗?
感谢。