[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 332
  • Last Modified:

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.

0
skiritis13
Asked:
skiritis13
  • 3
  • 3
2 Solutions
 
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
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
 
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

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now