VS2015를 사용하여 C#에서 긴 파일 경로에 대해이 p/invoke 메서드를 실행하려고합니다. 그러나 EFileAccess EFileShare ECreationDisposition EFileAttributes는 네임 스페이스에 없습니다. FileAccess, FileShare, FileMode 및 FileAttributes로 변경하면 오류가 사라집니다. 이러한 유형은 문맥에서 상호 교환 가능합니까? 내 프로젝트에서 내가 누락 된 부분은 무엇입니까?C# P/Invoke 누락 된 형식
using System;
using System.IO;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
internal static extern SafeFileHandle CreateFile(
string lpFileName, EFileAccess dwDesiredAccess, EFileShare dwShareMode,
IntPtr lpSecurityAttributes, ECreationDisposition dwCreationDisposition,
EFileAttributes dwFlagsAndAttributes, IntPtr hTemplateFile);
public static void TestCreateAndWrite(string fileName) {
string formattedName = @"\\?\" + fileName;
// Create a file with generic write access
SafeFileHandle fileHandle = CreateFile(formattedName,
EFileAccess.GenericWrite, EFileShare.None, IntPtr.Zero,
ECreationDisposition.CreateAlways, 0, IntPtr.Zero);
// Check for errors
int lastWin32Error = Marshal.GetLastWin32Error();
if (fileHandle.IsInvalid) {
throw new System.ComponentModel.Win32Exception(lastWin32Error);
}
// Pass the file handle to FileStream. FileStream will close the
// handle
using (FileStream fs = new FileStream(fileHandle,
FileAccess.Write)) {
fs.WriteByte(80);
fs.WriteByte(81);
fs.WriteByte(83);
fs.WriteByte(84);
}
}
'네임 스페이스에 잘 있지 않습니다. 당신은 그것을 정의해야합니다. 나는 한번 동등성을 확인했다는 것을 기억합니다. 일부는 동급이었고 일부는 그렇지 않았습니다. – usr
하지만 그들은 kernell32.dll – Yangrui