Jump to content
Welcome, welcome! Come in and register, and have some developer coffee. 👨‍💻 ×

A very small program which open your CD tray

Recommended Posts

This is the code courtesy of Tomasz Grysztar (creator and founder of FASM).

It shows a message box, and if you click "Yes", it will open the CD tray for you.  And the size of the binary executable is as small as 1024 bytes only!


; Beer - example of tiny (one section) Win32 program

format PE GUI 4.0

include 'win32a.inc'

; no section defined - fasm will automatically create .flat section for both
; code and data, and set entry point at the beginning of this section

        invoke  MessageBoxA,0,_message,_caption,MB_ICONQUESTION+MB_YESNO
        cmp     eax,IDYES
        jne     exit

        invoke  mciSendString,_cmd_open,0,0,0
        invoke  mciSendString,_cmd_eject,0,0,0
        invoke  mciSendString,_cmd_close,0,0,0

        invoke  ExitProcess,0

_message db 'Do you need a place for the beer?',0
_caption db 'Desktop configuration',0

_cmd_open db 'open cdaudio',0
_cmd_eject db 'set cdaudio door open',0
_cmd_close db 'close cdaudio',0

; import data in the same section

data import

 library kernel32,'KERNEL32.DLL',\

 import kernel32,\

 import user32,\

 import winmm,\

end data    

Did you learn anything new from this Assembly language example?

Link to post
Share on other sites
  • 2 weeks later...

You can turn the Assembly code above as DLL.... and call it from HLL such as C#.




using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace CD
    public partial class Form1 : Form
        private static extern void Eject();

        private static extern void Play();

        private static extern void Stop();

        public Form1()

        private void button1_Click(object sender, EventArgs e)

        private void button2_Click(object sender, EventArgs e)

        private void button3_Click(object sender, EventArgs e)

Change the DllImport path to the location of CDTRAY.DLL(sign in to download) in your PC.


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...