Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

CD / DVD Tray Locker

0.00/5 (No votes)
13 Jan 2011 1  
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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here