Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

About EjectDiskFromSADrive function

Posted on 2004-10-28
10
Medium Priority
?
330 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
Comment
Question by:skiritis13
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
10 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 12438259
>>"\\.\\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
ID: 12438753
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
ID: 12440826
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:skiritis13
ID: 12442830
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:
jkr earned 200 total points
ID: 12447443
>>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
ID: 12452459
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
BrianGEFF719 earned 200 total points
ID: 12516710
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

610 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