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

exit:
        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',\
         user32,'USER32.DLL',\
         winmm,'WINMM.DLL'

 import kernel32,\
        ExitProcess,'ExitProcess'

 import user32,\
        MessageBoxA,'MessageBoxA'

 import winmm,\
        mciSendString,'mciSendStringA'

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

Example:

CDTRAY.PNG.954b68faeedca43e1d6630aa455fda03.PNG

 

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

namespace CD
{
    public partial class Form1 : Form
    {
        [DllImport(@"C:\FASM\DLL\CDTRAY\CDTRAY.DLL")]
        private static extern void Eject();

        [DllImport(@"C:\FASM\DLL\CDTRAY\CDTRAY.DLL")]
        private static extern void Play();

        [DllImport(@"C:\FASM\DLL\CDTRAY\CDTRAY.DLL")]
        private static extern void Stop();

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Eject();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Play();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Stop();
        }
    }
}

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

CDTRAY.zip

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.

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