Click here to Skip to main content
15,881,204 members
Articles / Desktop Programming / Win32
Alternative
Tip/Trick

CD / DVD Tray Locker

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
13 Jan 2011CPOL 10.4K   2   6
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.

C#
[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:

C++
IntPtr deviceHandle = CreateFile(
            fileName,
            GENERIC_READ,
            FILE_SHARE_READ | FILE_SHARE_WRITE,
            ref securityAttributes,
            OPEN_EXISTING,
            FILE_ATTRIBUTE_NORMAL,
            IntPtr.Zero);

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) InfernoRed Technologies
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralHad confirmation for Microsoft, optional parameters should n... Pin
DaveyM6921-Apr-11 2:20
professionalDaveyM6921-Apr-11 2:20 
GeneralAccording to a comment on Connect, _opt doesn't mean optiona... Pin
DaveyM6915-Jan-11 0:44
professionalDaveyM6915-Jan-11 0:44 
GeneralI have filed a bug report at https://connect.microsoft.com/V... Pin
DaveyM6914-Jan-11 7:18
professionalDaveyM6914-Jan-11 7:18 
GeneralHi guys, I just figured this out myself this morning and cam... Pin
DaveyM6913-Jan-11 21:38
professionalDaveyM6913-Jan-11 21:38 
GeneralIt is definately strange to think that the optional paramete... Pin
Steve Maier13-Jan-11 7:37
professionalSteve Maier13-Jan-11 7:37 
GeneralI wonder what really happened here. The parameter is part of... Pin
Luc Pattyn13-Jan-11 6:42
sitebuilderLuc Pattyn13-Jan-11 6:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.