Open & Close Optical Disk Drive: Difference between revisions
(forgot category :)) |
(→Further Reading: typo in wikilinking) |
||
Line 40: | Line 40: | ||
*[http://msdn.microsoft.com/library/en-us/multimed/htm/_win32_multimedia_command_strings.asp Command String Reference from MSDN] | *[http://msdn.microsoft.com/library/en-us/multimed/htm/_win32_multimedia_command_strings.asp Command String Reference from MSDN] | ||
[Category:Disk, Path & File Functions] | [[Category:Disk, Path & File Functions]] |
Revision as of 20:38, 16 March 2006
I sorted out the WinAPI Calls for open and close CD/DVD Drives. Note that if you have more than one drive installed, these calls will affect only the primary one.
The Basics
By researching on the web, I found that you need to use the WinAPI function mciSendString to send a so called command string to the drive. It's implemented as ANSI version from on Win95 (mciSendStringA) and as Unicode version from Win2000, XP and above (mciSendStringU). It's located in winmm.dll in the system32 directory.
From MSDN we get the right syntax definition:
MCIERROR mciSendString( LPCTSTR lpszCommand, // Pointer to a null-terminated string that specifies an MCI command string. LPTSTR lpszReturnString, // Pointer to a buffer that receives return information. UINT cchReturn, // Size, in characters, of the return buffer specified by the lpszReturnString parameter. HANDLE hwndCallback // Handle to a callback window if the "notify" flag was specified in the command string. );
So lets translate it to a NSIS System.dll Plugin call:
System::Call "winmm::mciSendStringA(t 'command string', t .s, i ${NSIS_MAX_STRLEN},i $HWNDPARENT)i .s"
Note, that here I used the stack for any ouput (.s). I also used the ANSI version as you normally don't need to use Unicode anyway. As buffer size I recommend to always use ${NSIS_MAX_STRLEN} for any call you use, except if you want a smaller string for some reason. As callback handle of course set the handle of the installer ($HWNDPARENT).
For the command string having his own complex syntax, I sorted the two interesting ones out:
Open the Drive
System::Call "winmm::mciSendStringA(t 'set cdaudio door open', t .r0, i ${NSIS_MAX_STRLEN},i $HWNDPARENT)i .r1"
Close the Drive
System::Call "winmm::mciSendStringA(t 'set cdaudio door close', t .r0, i ${NSIS_MAX_STRLEN},i $HWNDPARENT)i .r1"