Open & Close Optical Disk Drive: Difference between revisions
(Undo revision 18063 by 195.242.186.10 (Talk)) |
|||
Line 31: | Line 31: | ||
</highlight-nsis> | </highlight-nsis> | ||
Hi I am so excited I found your wegpabe, I really found you by mistake, while I was researching on Google for something else, Anyhow I am here now and would just like to say kudos for a fantastic post and a all round interesting blog (I also love the theme/design), I don’t have time to browse it all at the minute but I have saved it and also added in your RSS feeds, so when I have time I will be back to read a lot more, Please do keep up the fantastic work. | |||
=== Output and Return === | === Output and Return === |
Revision as of 11:23, 15 May 2013
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"
Hi I am so excited I found your wegpabe, I really found you by mistake, while I was researching on Google for something else, Anyhow I am here now and would just like to say kudos for a fantastic post and a all round interesting blog (I also love the theme/design), I don’t have time to browse it all at the minute but I have saved it and also added in your RSS feeds, so when I have time I will be back to read a lot more, Please do keep up the fantastic work.
Output and Return
Note that you may not want to get any output. You then just can use t .n instead of t .r0 (or any other variable). Same for any other output. See the System Plugin Readme for more information about interaction with NSIS variables.