Solved

About EjectDiskFromSADrive function

Posted on 2004-10-28
323 Views
Last Modified: 2008-01-16
i'd like a word or two about how to use this function EjectDiskFromSADrive.
I am trying to eject my cdrom drive simply using the following code, ALTHOUGH i am not really confident that i am doing it right.I'd like to know if this is the function to use to eject the cdrom and how to use it right.

int main()
{
DWORD ret = 0;
ret = EjectDiskFromSADrive( NULL, NULL, "\\.\\Cdrom0", NULL, NULL, NULL, NTMS_EJECT_FORCE );
switch(ret)
{
case ERROR_ACCESS_DENIED: printf("NTMS_CONTROL_ACCESS to the library is denied. Other security errors are also possible, but they would indicate a security subsystem error."); break;
case ERROR_DATABASE_FAILURE: printf("The database is inaccessible or damaged."); break;
case ERROR_DATABASE_FULL: printf("The database is full."); break;
case ERROR_DEVICE_NOT_AVAILABLE: printf("The library is disabled."); break;
case ERROR_INVALID_HANDLE: printf("The session ID is invalid or missing."); break;
case ERROR_INVALID_OPERATION: printf("A stop was performed on an invalid operation ID."); break;
case ERROR_INVALID_PARAMETER: printf("A library ID or operation ID pointer is missing."); break;
case ERROR_LIBRARY_OFFLINE: printf("The library ID refers to an offline library that cannot eject media."); break;
case ERROR_MEDIA_NOT_AVAILABLE: printf("The media is disabled."); break;
case ERROR_NOT_ENOUGH_MEMORY: printf("There was an allocation failure during processing."); break;
case ERROR_SUCCESS: printf("The eject operation was successful."); break;
};

return 0;
}

I always get the ERROR_INVALID_PARAMETER error.
I'd like some help. the msnd is not very helpful.
Thanx.

0
Question by:skiritis13
    7 Comments
     
    LVL 86

    Expert Comment

    by:jkr
    >>"\\.\\Cdrom0"

    That should be

    "\\\\.\\Cdrom0"

    Thus the 'invalid parameter' error. See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devio/base/ejectdiskfromsadrive.asp ("EjectDiskFromSADrive"):

    lpDeviceName
    [in] Name of the device to eject. For example, \\.\Cdrom0 or \\.\PhysicalDriveX (where X is the number of the drive being accessed).

    As backslashes need to be doubled, "\\\\.\\Cdrom0" is the correct value.
    0
     

    Author Comment

    by:skiritis13
    jkr
    sorry to break it to you but i already did that.
    the results are the same. the 4 backslashes doesn't change something.
    so i'm back at the same point.
    0
     
    LVL 86

    Expert Comment

    by:jkr
    Um, and have you tried supplying the dialog box parameters that you st to NULL? I.e.:

     hWnd
        [in] Handle to a dialog box window for user confirmation.
    lpTitle
        [in] Title displayed in a dialog box to get user input.
    lpMessage
        [in] Message displayed in a dialog box to get user input.
    0
     

    Author Comment

    by:skiritis13
    Still no luck even if i change tha params to  this

    EjectDiskFromSADrive( NULL, NULL, "\\\\.\\Cdrom0", NULL, "Title", "Message", NTMS_EJECT_FORCE );

    I do not think the hWnd param should be sth other than NULL because that just means that the desktop owns the Messagebox.

    Any help from anyone???
    I'm increasing the points.
    0
     
    LVL 86

    Accepted Solution

    by:
    >>I do not think the hWnd param should be sth other than NULL

    No, the docs *explicitly* state "Handle to a dialog box window for user confirmation"
    0
     

    Author Comment

    by:skiritis13
    OK i hear you...
    Now i get the same error using the function like this:

    DWORD ret = 0;
    HWND hwnd = GetDesktopWindow();
    ret = EjectDiskFromSADrive( NULL, NULL, "\\\\.\\Cdrom0", hwnd, "Eject", "Eject", NTMS_EJECT_FORCE );

    ....
    0
     
    LVL 19

    Assisted Solution

    by:BrianGEFF719
    Have you Considered EjectNtmsMedia??

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devio/base/ejectntmsmedia.asp


    I think this might work better for you.


    -Brian
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
    Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
    The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
    The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

    877 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now