Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call "CreateFile" in C#?

Tags:

c#

pinvoke

After getting so much information about retrieving .MBR from a storage device, conclusion is to use P/Invoke to call CreateFile.

But how this can be done in C#? Please illustrate! Your help will be greatly appreciated!!!

like image 395
yen Avatar asked Jan 05 '09 13:01

yen


1 Answers

[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

like image 72
David Brown Avatar answered Sep 28 '22 18:09

David Brown