如何在C#中调用“CreateFile”?

时间:2009-01-05 13:10:54

标签: c# pinvoke

在获得有关retrieving .MBR from a storage device的大量信息后,结论是使用P / Invoke来调用CreateFile

但是如何在C#中完成这项工作?请说明!非常感谢您的帮助!!!

1 个答案:

答案 0 :(得分:19)

[DllImport("kernel32.dll", CharSet = CharSet.Auto, 
    CallingConvention = CallingConvention.StdCall, 
    SetLastError = true)]
public static extern SafeFileHandle CreateFile(
    string lpFileName,
    uint dwDesiredAccess,
    uint dwShareMode,
    IntPtr SecurityAttributes,
    uint dwCreationDisposition,
    uint dwFlagsAndAttributes,
    IntPtr hTemplateFile
);

http://pinvoke.net/default.aspx/kernel32/CreateFile.html