Click here to Skip to main content
15,914,225 members
Home / Discussions / C#
   

C#

 
GeneralRe: calling Web URL from desktop application Pin
sachees12314-Apr-09 2:10
sachees12314-Apr-09 2:10 
RantRe: calling Web URL from desktop application Pin
musefan14-Apr-09 2:20
musefan14-Apr-09 2:20 
AnswerRe: calling Web URL from desktop application Pin
Luc 64801114-Apr-09 2:56
Luc 64801114-Apr-09 2:56 
QuestionCHM file Editor Pin
Sajjad Leo14-Apr-09 0:36
Sajjad Leo14-Apr-09 0:36 
QuestionCopying partitions by kernel32 methods Pin
LordZoster14-Apr-09 0:29
LordZoster14-Apr-09 0:29 
Questionanimations on Win mobile 5.0 Pin
Deepali Khalkar14-Apr-09 0:27
Deepali Khalkar14-Apr-09 0:27 
AnswerRe: animations on Win mobile 5.0 Pin
raghebamer14-Apr-09 0:45
raghebamer14-Apr-09 0:45 
QuestionEjecting a CD opened by explorer Pin
LordZoster14-Apr-09 0:25
LordZoster14-Apr-09 0:25 
hallo
i wrote a small system tray utility to eject the CD, it uses Kernel32 via interop to access CreateFile, DeviceIOControl and CloseHandle methods (cannot use WMI).
It works fine unless the CD content is being viewed in a explorer window, or "My computer" window is open (i.e.: all drive units listed).
It seems that explorer locks the drive unit during these two views: any idea on how to overcome this?

this is an extract of the code:

// Constants used in DLL methods
        const uint GENERICREAD = 0x80000000;
        const uint OPENEXISTING = 3;
        const uint IOCTL_STORAGE_EJECT_MEDIA = 2967560;
        const int INVALID_HANDLE = -1;
        const uint DRIVE_CDROM = 5; 

        // File Handle
        private static IntPtr fileHandle;
        private static uint returnedBytes;

        // Use Kernel32 via interop to access required methods

        // Get a File Handle
        [DllImport("kernel32", SetLastError = true)]
        static extern IntPtr CreateFile(string fileName,
        uint desiredAccess,
        uint shareMode,
        IntPtr attributes,
        uint creationDisposition,
        uint flagsAndAttributes,
        IntPtr templateFile);

        [DllImport("kernel32", SetLastError = true)]
        static extern int CloseHandle(IntPtr driveHandle);

        [DllImport("kernel32", SetLastError = true)]
        static extern bool DeviceIoControl(IntPtr driveHandle,
        uint IoControlCode,
        IntPtr lpInBuffer,
        uint inBufferSize,
        IntPtr lpOutBuffer,
        uint outBufferSize,
        ref uint lpBytesReturned,
        IntPtr lpOverlapped);

        [DllImport("kernel32", SetLastError = true)]
        static extern int GetDriveType(string driveLetter);

...

public static void Eject(string driveLetter)
        {
            try
            {
                // Create an handle to the drive
                fileHandle = CreateFile(driveLetter,
                GENERICREAD,
                0,
                IntPtr.Zero,
                OPENEXISTING,
                0,
                IntPtr.Zero);

                if ((int)fileHandle != INVALID_HANDLE)
                {
                    // Eject the disk
                    DeviceIoControl(fileHandle,
                    IOCTL_STORAGE_EJECT_MEDIA,
                    IntPtr.Zero, 0,
                    IntPtr.Zero, 0,
                    ref returnedBytes,
                    IntPtr.Zero);
                }

            }
            catch
            {
                throw new Exception(Marshal.GetLastWin32Error().ToString());
            }
            finally
            {
                // Close Drive Handle
                CloseHandle(fileHandle);
                fileHandle = IntPtr.Zero;
            }
        }

AnswerRe: Ejecting a CD opened by explorer Pin
Giorgi Dalakishvili14-Apr-09 0:57
mentorGiorgi Dalakishvili14-Apr-09 0:57 
GeneralRe: Ejecting a CD opened by explorer Pin
LordZoster14-Apr-09 4:20
LordZoster14-Apr-09 4:20 
GeneralRe: Ejecting a CD opened by explorer Pin
Giorgi Dalakishvili14-Apr-09 6:11
mentorGiorgi Dalakishvili14-Apr-09 6:11 
QuestionWMP how show picture.... Pin
VisualLive14-Apr-09 0:23
VisualLive14-Apr-09 0:23 
AnswerRe: WMP how show picture.... Pin
Eddy Vluggen14-Apr-09 1:22
professionalEddy Vluggen14-Apr-09 1:22 
GeneralRe: WMP how show picture.... Pin
musefan14-Apr-09 1:46
musefan14-Apr-09 1:46 
GeneralRe: WMP how show picture.... Pin
Eddy Vluggen14-Apr-09 6:19
professionalEddy Vluggen14-Apr-09 6:19 
AnswerRe: WMP how show picture.... Pin
musefan14-Apr-09 1:41
musefan14-Apr-09 1:41 
Questionhow to scroll the text from bottom to top Pin
mist_psycho14-Apr-09 0:13
mist_psycho14-Apr-09 0:13 
QuestionRe: how to scroll the text from bottom to top Pin
Eddy Vluggen14-Apr-09 1:19
professionalEddy Vluggen14-Apr-09 1:19 
AnswerRe: how to scroll the text from bottom to top Pin
mist_psycho14-Apr-09 4:40
mist_psycho14-Apr-09 4:40 
AnswerRe: how to scroll the text from bottom to top Pin
Eddy Vluggen14-Apr-09 6:27
professionalEddy Vluggen14-Apr-09 6:27 
GeneralRe: how to scroll the text from bottom to top Pin
mist_psycho14-Apr-09 19:39
mist_psycho14-Apr-09 19:39 
GeneralRe: how to scroll the text from bottom to top Pin
Eddy Vluggen14-Apr-09 22:39
professionalEddy Vluggen14-Apr-09 22:39 
QuestionResponse Headers Pin
grewin13-Apr-09 23:49
grewin13-Apr-09 23:49 
AnswerRe: Response Headers Pin
Eddy Vluggen14-Apr-09 1:18
professionalEddy Vluggen14-Apr-09 1:18 
GeneralRe: Response Headers Pin
grewin20-Apr-09 21:46
grewin20-Apr-09 21:46 

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.