65.9K
CodeProject is changing. Read more.
Home

CD / DVD Tray Locker

emptyStarIconemptyStarIconemptyStarIconemptyStarIconemptyStarIcon

0/5 (0 vote)

Jan 13, 2011

CPOL
viewsIcon

11270

To get this to work in .NET 4, you have to change the DLLImport signature.[DllImport("kernel32.dll", SetLastError = true)]private static extern IntPtr CreateFile( string lpFileName, uint dwDesiredAccess, int dwShareMode, ref SECURITY_ATTRIBUTES lpSecurityAttributes, ...

To get this to work in .NET 4, you have to change the DLLImport signature.
[DllImport("kernel32.dll", SetLastError = true)]
private static extern IntPtr CreateFile(
    string lpFileName,
    uint dwDesiredAccess,
    int dwShareMode,
    ref SECURITY_ATTRIBUTES lpSecurityAttributes,
    int dwCreationDisposition,
    int dwFlagsAndAttributes,
    IntPtr template);
Then change the usage to be this:
IntPtr deviceHandle = CreateFile(
            fileName,
            GENERIC_READ,
            FILE_SHARE_READ | FILE_SHARE_WRITE,
            ref securityAttributes,
            OPEN_EXISTING,
            FILE_ATTRIBUTE_NORMAL,
            IntPtr.Zero);