td win32asm 210.asm

11
td_win32asm_210.asm ;============================================================================== ; Test Department's WINDOWS 32 BIT x86 ASSEMBLY TUTORIAL'S 210 ;============================================================================== ;============================================================================== ; ==> Part 210 : simple audio cd player ;------------------------------------------------------------------------------ ; Hello again, ; Today we program a simple Audio CD Player. You need the multimedia reference. ; On my homepage you can find a link to this reference ( Mmedia.hlp ). ; Load the multimedia reference & search for "Classifications of MCI Commands". ; This seems to be a good starting point. ; There are two ways to work with multimedia devices: ; 1. API "mciSendCommand" most times uses a structure. ; 2. API "mciSendString" works with strings. ; However here I use API "mciSendCommand". You must also include winmm.lib. ; All "buttons" are menu bar items defined in the resource file ( rsrc.rc ) !!! ; Any question ? Refere to the tutorials before or email me ... ; "lpfnWndProc" is a pointer to the subroutine label "WindowProc" ( WP1 ) where ; all the action code for this main window resist. ; "lpfnWndProc" is part of WndClassEx structure used by API RegisterClassEx. ;============================================================================== ; Assembler directives ;------------------------------------------------------------------------------ .386 ; specifies the processor our program want run on .Model Flat ,StdCall ; always the same for Win95 (32 Bit) option casemap:none ; case sensitive !!! ;============================================================================== ; Include all files where API functions resist you want use ; You must set the correct path to the include and library files ;------------------------------------------------------------------------------ include D:\Masm32\include\windows.inc includelib kernel32.lib includelib user32.lib includelib winmm.lib ;============================================================================== ; Declaration of used API functions,take a look into WIN32.HLP and *.inc files ;------------------------------------------------------------------------------ GetModuleHandleA PROTO :DWORD LoadIconA PROTO :DWORD,:DWORD LoadCursorA PROTO :DWORD,:DWORD RegisterClassExA PROTO :DWORD CreateWindowExA PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD, :DWORD,:DWORD,:DWORD,:DWORD,:DWORD ShowWindow PROTO :DWORD,:DWORD UpdateWindow PROTO :DWORD GetMessageA PROTO :DWORD,:DWORD,:DWORD,:DWORD TranslateMessage PROTO :DWORD DispatchMessageA PROTO :DWORD PostQuitMessage PROTO :DWORD Page 1

Upload: z4rm4r

Post on 03-Dec-2015

5 views

Category:

Documents


0 download

DESCRIPTION

Skola asemblera TD zakon

TRANSCRIPT

Page 1: Td Win32asm 210.Asm

td_win32asm_210.asm;==============================================================================; Test Department's WINDOWS 32 BIT x86 ASSEMBLY TUTORIAL'S 210;==============================================================================

;==============================================================================; ==> Part 210 : simple audio cd player;------------------------------------------------------------------------------; Hello again,; Today we program a simple Audio CD Player. You need the multimedia reference.; On my homepage you can find a link to this reference ( Mmedia.hlp ).; Load the multimedia reference & search for "Classifications of MCI Commands".; This seems to be a good starting point.; There are two ways to work with multimedia devices:; 1. API "mciSendCommand" most times uses a structure.; 2. API "mciSendString" works with strings.; However here I use API "mciSendCommand". You must also include winmm.lib.; All "buttons" are menu bar items defined in the resource file ( rsrc.rc ) !!!; Any question ? Refere to the tutorials before or email me ...; "lpfnWndProc" is a pointer to the subroutine label "WindowProc" ( WP1 ) where; all the action code for this main window resist.; "lpfnWndProc" is part of WndClassEx structure used by API RegisterClassEx.

;==============================================================================; Assembler directives;------------------------------------------------------------------------------.386 ; specifies the processor our program want run on.Model Flat ,StdCall ; always the same for Win95 (32 Bit)option casemap:none ; case sensitive !!!

;==============================================================================; Include all files where API functions resist you want use; You must set the correct path to the include and library files;------------------------------------------------------------------------------include D:\Masm32\include\windows.incincludelib kernel32.libincludelib user32.libincludelib winmm.lib

;==============================================================================; Declaration of used API functions,take a look into WIN32.HLP and *.inc files;------------------------------------------------------------------------------GetModuleHandleA PROTO :DWORDLoadIconA PROTO :DWORD,:DWORDLoadCursorA PROTO :DWORD,:DWORDRegisterClassExA PROTO :DWORDCreateWindowExA PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD, :DWORD,:DWORD,:DWORD,:DWORD,:DWORDShowWindow PROTO :DWORD,:DWORDUpdateWindow PROTO :DWORDGetMessageA PROTO :DWORD,:DWORD,:DWORD,:DWORDTranslateMessage PROTO :DWORDDispatchMessageA PROTO :DWORDPostQuitMessage PROTO :DWORD

Page 1

Page 2: Td Win32asm 210.Asm

td_win32asm_210.asmDefWindowProcA PROTO :DWORD,:DWORD,:DWORD,:DWORDExitProcess PROTO :DWORDMessageBoxA PROTO :DWORD,:DWORD,:DWORD,:DWORDDestroyWindow PROTO :DWORDSendMessageA PROTO :DWORD,:DWORD,:DWORD,:DWORDmciSendCommandA PROTO :DWORD,:DWORD,:DWORD,:DWORDmciGetErrorStringA PROTO :DWORD,:DWORD,:DWORD

;==============================================================================; .const = the constants area starts here, constants are defined and fixed;------------------------------------------------------------------------------.const; - Parameter MAIN WINDOW CallBack Procedure ( API=RegisterClassExA ) -WP1_CallBack equ [ebp+4] ;return addressWP1_hWnd equ [ebp+8] ;handle of window who receives messageWP1_uMsg equ [ebp+12] ;the message numberWP1_wParam equ [ebp+16] ;extra info about the messageWP1_lParam equ [ebp+20] ;extra info about the message

;==============================================================================; .Data = the data area starts here, datas are defined but not fixed;------------------------------------------------------------------------------.DataIconName db "TDIcon",0 ;icon name in rc fileMenuName db "TDMenu",0 ;menu name in rc fileClassName db "TDWinClass",0 ;name of windows classWindowName db "Test Department",0 ;window name titel barMB1Titel db "Realy Exit ?",0 ;message box nameMB1Text db "Your choice ...",0 ;message box textMB2Titel db "MCI_ErrorString",0 ;message box nameMB2Text db 104h dup(0) ;message box textmci_pause_flag dd 0h ;

;==============================================================================; .Data? = the data? area starts here, not defined and not fixed;------------------------------------------------------------------------------.data?align 4; - MCI_OPEN_PARMS Structure ( API=mciSendCommand ) -open_dwCallback dd ?open_wDeviceID dd ?open_lpstrDeviceType dd ?open_lpstrElementName dd ?open_lpstrAlias dd ?

align 4; - MCI_SET_PARMS Structure ( API=mciSendCommand ) -set_dwCallback dd ?set_dwTimeFormat dd ?set_dwAudio dd ?

align 4; - MCI_PLAY_PARMS Structure ( API=mciSendCommand ) -

Page 2

Page 3: Td Win32asm 210.Asm

td_win32asm_210.asmplay_dwCallback dd ?play_dwFrom dd ?play_dwTo dd ?

align 4; - MCI_GENERIC_PARMS Structure ( API=mciSendCommand ) -generic_dwCallback dd ?

align 4; - WndClassEx Structure ( API=RegisterClassExA ) -cbSize dd ? ;size in bytes of this structurestyle dd ? ;window stylelpfnWndProc dd ? ;address of user proc functioncbclsExtra dd ? ;extra bytes to allocate set to 0cbWndExtra dd ? ;extra bytes class directive, rc filehInstance dd ? ;program handle(API=GetModuleHandleA)hIcon dd ? ;handle of icon (API=LoadIconA)hcursor dd ? ;handle of cursor (API=LoadCursor)hbrBackground dd ? ;background color, 0=transparentlpszMenuName dd ? ;name of menu class in resource filelpszClassName dd ? ;name of windows this window classhIconSm dd ? ;iconhandle 0=search in resource file

align 4; - Msg Structure ( API=GetMessageA ) - member POINT = POINT structurehWnd dd ? ;handle of window who receives messagemessage dd ? ;the message numberwParam dd ? ;extra info about the messagelParam dd ? ;extra info about the message time dd ? ;time the message was posted xpt dd ? ;cursor x-position, POINT strucypt dd ? ;cursor x-position, POINT struc

;==============================================================================; .CODE = our code area starts here Main = label of our program code;------------------------------------------------------------------------------.CodeMain:

;==============================================================================; Always get your program ID first (API=GetModuleHandleA);------------------------------------------------------------------------------push 0h ;lpModuleHandle, 0=get program handlecall GetModuleHandleA ;- API Function -mov hInstance,eax ;return value in eax=handle of program

;==============================================================================; The API function "RegisterClassExA" registers a window class; This API needs a "WNDCLASSEX" structure so we fill it with correct values;------------------------------------------------------------------------------mov cbSize,30h ;size in bytes of WNDCLASSEX structuremov style,3h ;window stylemov lpfnWndProc,OFFSET WP1 ;address of user lpfnWndProc function

Page 3

Page 4: Td Win32asm 210.Asm

td_win32asm_210.asmmov cbclsExtra,0h ;extra bytes to allocate set to 0mov cbWndExtra,0h ;class directive in rc filemov hbrBackground,16 ;background, COLOR_BTNFACE(parameter+1)mov lpszMenuName,OFFSET MenuName ;menu name in resource filemov lpszClassName,OFFSET ClassName ;name of windows classmov hIconSm,0h ;iconhandle 0=search in rc file;------------------------------------------------------------------------------; API "LoadIconA" loads an icon defined in the resource file and store the; handle in the "WNDCLASSEX" structure;------------------------------------------------------------------------------push OFFSET IconName ;icon-string or icon resource idpush hInstance ;our program handlecall LoadIconA ;- API Function -mov hIcon,eax ;handle of newly loaded icon;------------------------------------------------------------------------------; API "LoadCursorA" loads a default system cursor, in this case we must set; hInstance to 0 and lpCursorName to a default system cursor value, here 32512; Then we store the cursor handle in the "WNDCLASSEX" structure;------------------------------------------------------------------------------push 32512 ;lpCursorName,default value in dezimalpush 0h ;hInstance, 0=default system cursorcall LoadCursorA ;- API Function -mov hcursor,eax ;handle of the cursor;------------------------------------------------------------------------------; Now, after filled the "WNDCLASSEX" structure we call API "RegisterClassEx";------------------------------------------------------------------------------push OFFSET cbSize ;pointer to WNDCLASSEX structurecall RegisterClassExA ;- API Function -

;==============================================================================; API "CreateWindowExA" creates an overlapped, pop-up, or child window with an; extended style. The return value in EAX is the handle of the new window.; This API sends a WM_CREATE message to the window procedure (WP1).;------------------------------------------------------------------------------push 0h ;lpParam, extra pointer data 0=no datapush hInstance ;hInstance, handle of our programpush 0h ;hMenu, handle window menu 0=class menupush 0h ;hWndParent, handle parent window 0=nopush 00000082h ;intnHeight, window height pixelpush 0100h ;intnWidth, window width pixelpush 00000040h ;inty, vertical position windowpush 00000140h ;intx, horizontal position windowpush 04CA0000h ;dwStyle, 0=no sysmenu/close buttonspush OFFSET WindowName ;lpWindowName, pointer to window namepush OFFSET ClassName ;lpClassName, pointer to class namepush 0300h ;dwExStyle, extra window style 0=nocall CreateWindowExA ;- API Function -mov hWnd,eax ;hwnd,return value=handle of window

;==============================================================================; API "ShowWindow" function sets the specified window's show state. ;------------------------------------------------------------------------------push 1h ;nCmdShow, show state 1=SW_SHOWNORMAL

Page 4

Page 5: Td Win32asm 210.Asm

td_win32asm_210.asmpush hWnd ;hwnd, handle of windowcall ShowWindow ;- API Function -

;==============================================================================; API "UpdateWindow" updates the area of the specified window by sending a; WM_PAINT message to the window if the window's update region is not empty.;------------------------------------------------------------------------------push hWnd ;hwnd, handle of windowcall UpdateWindow ;- API Function -

;==============================================================================; API "GetMessageA" retrieves a message & places it in the specified structure.;------------------------------------------------------------------------------LoopGetMessage:push 0h ;wMsgFilterMax, highest message valuepush 0h ;wMsgFilterMin, lowest message valuepush 0h ;hWnd, handle of window who gets msg.push OFFSET hWnd ;lpMsg, pointer to MSG structurecall GetMessageA ;- API Function -cmp eax,0h ;check if return value=0 (exit)je ExitPrg ;if return value is 0 goto LABEL

;==============================================================================; API "TranslateMessage" translates key code into ASCII character messages;------------------------------------------------------------------------------push OFFSET hWnd ;lpMSG, pointer to msg structurecall TranslateMessage ;- API Function - keyboard code

;==============================================================================; API "DispatchMessageA" function dispatches a message to a window procedure.;------------------------------------------------------------------------------push OFFSET hWnd ;lpMSG, pointer to msg structurecall DispatchMessageA ;- API Function -jmp LoopGetMessage ;check for message again, goto LABEL

;==============================================================================; Next we terminate our program (API=ExitProcess);------------------------------------------------------------------------------ExitPrg:push hInstance ;push our programm handle to exitcall ExitProcess ;- API Function -

;##############################################################################; The Window Procedure (API=RegisterClassExA) for this registered window.;------------------------------------------------------------------------------WP1:push ebp ;create stack framemov ebp,esp ;pushad ;push all register to the stack

mov eax,WP1_uMsg ;move the message number to eax;==============================================================================; WM_CREATE (value=01h) message received ?

Page 5

Page 6: Td Win32asm 210.Asm

td_win32asm_210.asm; Here we open the device and set the audio and time format.;------------------------------------------------------------------------------WP1_uMsg_01h:cmp eax,1h ;check if WM_CREATE message recievedjne WP1_uMsg_02h ;if not goto label;------------------------------------------------------------------------------; API "mciSendCommandA" here opens the device;------------------------------------------------------------------------------mov open_lpstrDeviceType,516 ;fill MCI_OPEN_PARMS structure ;MCI_DEVTYPE_CD_AUDIO = 516push OFFSET open_dwCallback ;dwParam, address MCI_OPEN_PARMS struc.push 3100h ;fdwCommand, ;MCI_OPEN_TYPE = 2000h ;MCI_OPEN_TYPE_ID = 1000h ;MCI_OPEN_SHAREABLE = 100hpush 0803h ;uMsg, command message, MCI_OPENpush 0h ;IDDevice, not used with MCI_OPENcall mciSendCommandA ;- API Function -call My_mciErrorString ;- SUBROUTINE -;------------------------------------------------------------------------------; API "mciSendCommandA" here sets the time format and audio format.; TMSF = track, minute, second, frame.;------------------------------------------------------------------------------mov set_dwTimeFormat,0Ah ;fill MCI_SET_PARMS structure ;MCI_FORMAT_TMSF = 0Ahmov set_dwAudio,6401h ;fill MCI_SET_PARMS structure ;MCI_SET_AUDIO_ALL = 4001h ;MCI_SET_ON = 2000h ;MCI_SET_TIME_FORMAT= 400hpush OFFSET set_dwCallback ;dwParam, address MCI_SET_PARMS struc.push 6401h ;fdwCommand, same as above push 080Dh ;uMsg, command message, MCI_SETpush open_wDeviceID ;IDDevice, given from MCI_OPEN abovecall mciSendCommandA ;- API Function -call My_mciErrorString ;- SUBROUTINE -jmp WP1_return ;

;==============================================================================; WM_DESTROY (value=02h) message received ?;------------------------------------------------------------------------------WP1_uMsg_02h:cmp eax,2h ;check if value=2h (WM_DESTROY)jne WP1_uMsg_111h ;if not 2h go to LABELcall My_CleanSystem ;- SubRoutine -;------------------------------------------------------------------------------; API "PostQuitMessage" indicates to Windows a request to terminate;------------------------------------------------------------------------------push 0h ;nExitCode, exit code=wParamcall PostQuitMessage ;- API Function -popad ;pop all register back from stackxor eax,eax ;set eax to 0 to exit our programmov esp,ebp ;delete stack framepop ebp ;

Page 6

Page 7: Td Win32asm 210.Asm

td_win32asm_210.asmret 10h ;return and clear stack

;==============================================================================; WM_COMMAND (value=111h) message recieved ?;------------------------------------------------------------------------------WP1_uMsg_111h:cmp eax,111h ;check if WM_COMMAND message recievedjne WP1_uMsg_112h ;if not goto label;------------------------------------------------------------------------------; Check extra message info menu control, "01"-"30" item in menu bar clicked;------------------------------------------------------------------------------WP1_wParam_01h:mov eax,WP1_wParam ;extra info about the message in axcmp ax,1Eh ;max. (30) ID of item in rc fileja WP1_wParam_0032h ;if above 1Eh (30 dezimal) goto LABELcwde ;convert word ax into doubleword eaxmov play_dwFrom,eax ;store starting track in structurecall My_mciSendCommandClose ;- SUBROUTINE -call My_mciErrorString ;- SUBROUTINE -;------------------------------------------------------------------------------; API "mciSendCommandA" here plays from the choosen track to the end of media; The resource ID is here also used for the starting track number !;------------------------------------------------------------------------------mov mci_pause_flag,0h ;set pause flag to 0hpush OFFSET play_dwCallback ;dwParam, address MCI_PLAY_PARMS struc.push 04h ;fdwCommand, MCI_FROMpush 0806h ;uMsg, command message, MCI_PLAYpush open_wDeviceID ;IDDevice, given from MCI_OPENcall mciSendCommandA ;- API Function -call My_mciErrorString ;- SUBROUTINE -jmp WP1_return;------------------------------------------------------------------------------; Extra message menu control, "MCI_ErrorString" item in menu bar,ID=32h clicked;------------------------------------------------------------------------------WP1_wParam_0032h:cmp ax,0032h ;ID of menu control in rc filejne WP1_wParam_0033h ;if not 0032h goto LABELcall My_mciErrorTextbox ;- SUBROUTINE -jmp WP1_return;------------------------------------------------------------------------------; Check extra message info menu control, "Exit" item in menu bar,ID=33h clicked;------------------------------------------------------------------------------WP1_wParam_0033h:cmp ax,0033h ;ID of menu control in rc filejne WP1_wParam_0051h ;if not 0033h goto LABEL;------------------------------------------------------------------------------; API "MessageBoxA" creates a message box, we can choose if we want exit;------------------------------------------------------------------------------push 4h ;uType, style, 4=MB_YESNO Buttonpush OFFSET MB1Titel ;lpCaption,pointer to title textpush OFFSET MB1Text ;lpText,pointer to text message boxpush WP1_hWnd ;handle of owner window 0=no ownercall MessageBoxA ;- API Function -

Page 7

Page 8: Td Win32asm 210.Asm

td_win32asm_210.asmcmp eax,6h ;if return value=6h (IDYES) then exitjne WP1_return ;if return value=7h (IDNO) goto LABEL;------------------------------------------------------------------------------; API "DestroyWindow" function destroys the given window if we want exit prg.;------------------------------------------------------------------------------push WP1_hWnd ;hwnd, handle of window to destroycall DestroyWindow ;- API Function -jmp WP1_return;------------------------------------------------------------------------------; Check extra message info menu control, "Play" item in menu bar,ID=51h clicked;------------------------------------------------------------------------------WP1_wParam_0051h:cmp ax,51h ;ID of item in rc filejne WP1_wParam_0052h ;if not 51h goto LABELcontinue_play:call My_mciSendCommandClose ;- SUBROUTINE -call My_mciErrorString ;- SUBROUTINE -;------------------------------------------------------------------------------; API "mciSendCommandA" here plays from track 1 to the end of media; If "Pause" was clicked before it plays from current position to end of media;------------------------------------------------------------------------------mov play_dwFrom,1h ;fill MCI_PLAY_PARMS struc., starttrackpush OFFSET play_dwCallback ;dwParam, address MCI_PLAY_PARMS struc.push 04h ;fdwCommand, MCI_FROMcmp mci_pause_flag,0h ;check pause flagje play_fromstart ;if pause flag=0h play from track 1pop eax ;pop MCI_FROM from the stackpush 0h ;if pause flag=1 play from current pos.play_fromstart:mov mci_pause_flag,0h ;set pause flag to 0h push 0806h ;uMsg, command message, MCI_PLAYpush open_wDeviceID ;IDDevice, given from MCI_OPENcall mciSendCommandA ;- API Function -call My_mciErrorString ;- SUBROUTINE -jmp WP1_return;------------------------------------------------------------------------------; Check extra message info menu control,"Pause" item in menu bar,ID=52h clicked; If the "Pause Flag" is 1 we jump direct to the Play function and continue;------------------------------------------------------------------------------WP1_wParam_0052h:cmp ax,52h ;ID of item in rc filejne WP1_wParam_0053h ;if not 52h goto LABELcmp mci_pause_flag,1h ;test pause flagje continue_play ;if pause flag=1 then continue playingmov mci_pause_flag,1h ;set pause flag to 1h;------------------------------------------------------------------------------; API "mciSendCommandA" here pauses playing the current track;------------------------------------------------------------------------------push OFFSET generic_dwCallback ;dwParam, MCI_GENERIC_PARMS structurepush 0h ;fdwCommand, 0h=no commandpush 0809h ;uMsg, command message, MCI_PAUSEpush open_wDeviceID ;IDDevice, given from MCI_OPENcall mciSendCommandA ;- API Function -

Page 8

Page 9: Td Win32asm 210.Asm

td_win32asm_210.asmcall My_mciErrorString ;- SUBROUTINE -jmp WP1_return;------------------------------------------------------------------------------; Check extra message info menu control,"Stop" item in menu bar,ID=53h clicked;------------------------------------------------------------------------------WP1_wParam_0053h:cmp ax,53h ;ID of item in rc filejne WP1_wParam_0054h ;if not 53h goto LABELmov mci_pause_flag,0h ;set pause flag to 0hcall My_mciSendCommandStop ;- SUBROUTINE -call My_mciErrorString ;- SUBROUTINE -jmp WP1_return;------------------------------------------------------------------------------; Check extra message info menu control, "Open" item in menu bar,ID=54h clicked;------------------------------------------------------------------------------WP1_wParam_0054h:cmp ax,0054h ;ID of menu control in rc filejne WP1_wParam_0055h ;if not 0054h goto LABEL;------------------------------------------------------------------------------; API "mciSendCommandA" here opens the cdrom door;------------------------------------------------------------------------------push OFFSET set_dwCallback ;dwParam, address MCI_SET_PARMS struc.push 0100h ;fdwCommand, MCI_SET_DOOR_OPENpush 080Dh ;uMsg, command message, MCI_SETpush open_wDeviceID ;IDDevice, given from MCI_OPENcall mciSendCommandA ;- API Function -call My_mciErrorString ;- SUBROUTINE -jmp WP1_return;------------------------------------------------------------------------------; Check extra message info menu control,"Close" item in menu bar,ID=55h clicked;------------------------------------------------------------------------------WP1_wParam_0055h:cmp ax,0055h ;ID of menu control in rc filejne WP1_return ;if not 0055h goto LABELcall My_mciSendCommandClose ;- SUBROUTINE -call My_mciErrorString ;- SUBROUTINE -jmp WP1_return

;==============================================================================; WM_SYSCOMMAND (value=112h) message recieved ?;------------------------------------------------------------------------------WP1_uMsg_112h:cmp eax,112h ;check if WM_COMMAND message recievedjne WP1_return ;if not goto labelmov eax,WP1_wParam ;extra info about the messagecmp eax,0F060h ;SC_CLOSE=0F060h received ?jne WP1_return ;call My_CleanSystem ;- SubRoutine -jmp WP1_return

;==============================================================================; API "DefWindowProcA" calls the window procedure to provide default processing; for any window messages that an application does not process.

Page 9

Page 10: Td Win32asm 210.Asm

td_win32asm_210.asm; This function ensures that every message is processed.; It is called with the same parameters received by the window procedure.;------------------------------------------------------------------------------WP1_return:popad ;pop all register from stackpush WP1_lParam ;extra info about the messagepush WP1_wParam ;extra info about the messagepush WP1_uMsg ;the message numberpush WP1_hWnd ;handle of window who receives messagecall DefWindowProcA ;- API Function -mov esp,ebp ;delete stack framepop ebp ;ret 10h ;return and clear stack;##############################################################################

;******************************************************************************; My own subroutine(s) for a compacter code resist here ...;------------------------------------------------------------------------------My_CleanSystem:call My_mciSendCommandStop ;- SUBROUTINE -call My_mciErrorString ;- SUBROUTINE -ret

My_mciErrorString:;------------------------------------------------------------------------------; API "mciGetErrorString" retrieves the last status message;------------------------------------------------------------------------------push 255 ;cchErrorText, length of textbufferpush OFFSET MB2Text ;lpszErrorText, address of textbufferpush eax ;fdwError, error code returned by APIcall mciGetErrorStringA ;- API Function -ret

My_mciErrorTextbox:;------------------------------------------------------------------------------; API "MessageBoxA" creates a message box, we can only click OK;------------------------------------------------------------------------------push 0h ;uType, style, 0=MB_OK Buttonpush OFFSET MB2Titel ;lpCaption,pointer to title textpush OFFSET MB2Text ;lpText,pointer to text message boxpush WP1_hWnd ;handle of owner window 0=no ownercall MessageBoxA ;- API Function -ret

My_mciSendCommandClose:;------------------------------------------------------------------------------; API "mciSendCommandA" here closes the cdrom door;------------------------------------------------------------------------------push OFFSET set_dwCallback ;dwParam, address MCI_SET_PARMS struc.push 0200h ;fdwCommand, MCI_SET_DOOR_CLOSEDpush 080Dh ;uMsg, command message, MCI_SETpush open_wDeviceID ;IDDevice, given from MCI_OPENcall mciSendCommandA ;- API Function -

Page 10

Page 11: Td Win32asm 210.Asm

td_win32asm_210.asmret

My_mciSendCommandStop:;------------------------------------------------------------------------------; API "mciSendCommandA" here stops playing the current track;------------------------------------------------------------------------------push OFFSET generic_dwCallback ;dwParam, MCI_GENERIC_PARMS structurepush 0h ;fdwCommand, 0h=no commandpush 0808h ;uMsg, command message, MCI_STOPpush open_wDeviceID ;IDDevice, given from MCI_OPENcall mciSendCommandA ;- API Function -ret;******************************************************************************

;==============================================================================; end Main = end of our program code;------------------------------------------------------------------------------end Main ;end of our program code, entry point

;==============================================================================; To create the exe file use this commands with your Microsoft Assembler/Linker;------------------------------------------------------------------------------; ml.exe /c /coff td_win32asm_210.asm ;asm command; rc.exe /v rsrc.rc ;rc command; cvtres.exe /machine:ix86 rsrc.res; link.exe /subsystem:windows td_win32asm_210.obj rsrc.obj ;link command;==============================================================================

Page 11