About EjectDiskFromSADrive function

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.

skiritis13Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jkrCommented:
>>"\\.\\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
skiritis13Author Commented:
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
jkrCommented:
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
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

skiritis13Author Commented:
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
jkrCommented:
>>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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
skiritis13Author Commented:
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
BrianGEFF719Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.