flat assembler
Message board for the users of flat assembler.

Index > Windows > mciSendString

Author
Thread Post new topic Reply to topic
me239



Joined: 06 Jan 2011
Posts: 200
me239 17 May 2011, 04:48
Hello! Today I was trying to make a mp3 player using the native mci, but haven't had much luck. Here is my code:
Code:
format PE GUI 4.0
include 'win32a.inc'
section '.code' readable executable
start:        
        invoke  mciSendString, close, 0, 0
        invoke  mciSendString, opcom, 0, 0
        invoke  mciSendString, play, 0, 0
        invoke  Sleep, -1
section '.data' data readable writeable
        close   db   "Close Mp3",0
        opcom   db   "Open C:\test.MP3 Alias Mp3",0
        play    db   "Play C:\test.mp3 from 0",0
section '.idata' import data readable writeable
        library kernel32, "KERNEL32.DLL",\
                winmm, "WINMM.DLL"
        import kernel32,\
               Sleep, "Sleep"
        import winmm,\
               mciSendString, "mciSendStringA"
    


Last edited by me239 on 17 May 2011, 21:12; edited 3 times in total
Post 17 May 2011, 04:48
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2909
Location: 0x77760000
typedef 17 May 2011, 05:38
hmmmm....i really never programmed with that api that much, but does the winmm.dll still stay in memory when your programm quits after calling ExitProcess?

maybe u shld add a message loop to see if that is the problem....
Post 17 May 2011, 05:38
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2909
Location: 0x77760000
typedef 17 May 2011, 05:40
also try defining the code section for clarity.
Post 17 May 2011, 05:40
View user's profile Send private message Reply with quote
me239



Joined: 06 Jan 2011
Posts: 200
me239 17 May 2011, 05:49
typedef wrote:
hmmmm....i really never programmed with that api that much, but does the winmm.dll still stay in memory when your programm quits after calling ExitProcess?

maybe u shld add a message loop to see if that is the problem....
Yes actually, that is the problem. How do I fix it? I added a jmp $ which just ran my cpu up to 50%.
Post 17 May 2011, 05:49
View user's profile Send private message Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler 17 May 2011, 06:11
Code:
format PE console

invoke  Sleep,-1    

_________________
This is a block of text that can be added to posts you make.
Post 17 May 2011, 06:11
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2909
Location: 0x77760000
typedef 17 May 2011, 08:26
or
CreateWindowEx,0,WC_DIALOG

SetWindowLong
PeekMessge,,,PM_REMOVE
TranslateMessage
DispatchMessage

and a procedure for handling the dlg.
i can not help that much right now because im on my psp and typing on it is a daunting task
Post 17 May 2011, 08:26
View user's profile Send private message Reply with quote
me239



Joined: 06 Jan 2011
Posts: 200
me239 17 May 2011, 20:19
I used the sleep, -1 and it worked, but I think I might try typedef's method. Also, does anyone know how to play the mp3 within the resource w/o making a temp file?
Post 17 May 2011, 20:19
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2909
Location: 0x77760000
typedef 17 May 2011, 22:04
Yeah I remember there's is a way of extracting it from resource directory during runtime and then playing it...
Post 17 May 2011, 22:04
View user's profile Send private message Reply with quote
me239



Joined: 06 Jan 2011
Posts: 200
me239 18 May 2011, 04:33
Hey, I just had a crazy idea. Can I register the mciSendString command to another process so my program just executes the command, but leaves it with something like explorer.exe?
Post 18 May 2011, 04:33
View user's profile Send private message Reply with quote
me239



Joined: 06 Jan 2011
Posts: 200
me239 18 May 2011, 05:03
I just found a quicker way than the sleep command. Use "Play Mp3 wait" instead of "Play Mp3 from 0". The wait forces the application to wait as long as the song lasts and then can allow you to exit.
Post 18 May 2011, 05:03
View user's profile Send private message Reply with quote
goldenspider



Joined: 16 May 2011
Posts: 38
goldenspider 10 Jun 2011, 04:56
Share the code.

Code:
;----------------------------------------------------------
; Program Name: playmp3.asm
; Purpose     : plays an mp3 file
; Date        : August 2008
; Author      : Yeoh HS
; FASM        : Built using Flat Assembler version 1.67.27
;               edited and compiled with FASM's IDE.
;----------------------------------------------------------
format PE CONSOLE 4.0
entry start

include 'win32axp.inc'

.data
    CRLF       db '',13,10,0  ; carriage return and linefeed
    cmd_open   db 'open explosion.mp3 type MPEGVideo Alias MP3',0
    cmd_play   db 'play MP3',0
    cmd_close  db 'close MP3',0
    nullstring db '',0
.code
start:

    invoke  mciSendString, cmd_close, nullstring, 0, 0
    invoke  mciSendString, cmd_open, nullstring, 0, 0
    invoke  mciSendString, cmd_play, nullstring, 0, 0

    cinvoke printf, CRLF
    cinvoke printf, 'Press the Enter key...'
    cinvoke getchar
    invoke  ExitProcess,0

section '.idata' import data readable writeable

library kernel32,'kernel32.dll',\
      user32,  'user32.dll',\
  winmm,   'winmm.dll',\
   msvcrt,  'msvcrt.dll'

include 'api\kernel32.inc'
include 'api\user32.inc'

import winmm,\
       mciSendString, 'mciSendStringA'

import msvcrt,\
       printf, 'printf',\
       getchar,'getchar'

; end of file
    
Post 10 Jun 2011, 04:56
View user's profile Send private message Reply with quote
me239



Joined: 06 Jan 2011
Posts: 200
me239 10 Jun 2011, 05:08
goldenspider wrote:
Share the code.

Code:
;----------------------------------------------------------
; Program Name: playmp3.asm
; Purpose     : plays an mp3 file
; Date        : August 2008
; Author      : Yeoh HS
; FASM        : Built using Flat Assembler version 1.67.27
;               edited and compiled with FASM's IDE.
;----------------------------------------------------------
format PE CONSOLE 4.0
entry start

include 'win32axp.inc'

.data
    CRLF       db '',13,10,0  ; carriage return and linefeed
    cmd_open   db 'open explosion.mp3 type MPEGVideo Alias MP3',0
    cmd_play   db 'play MP3',0
    cmd_close  db 'close MP3',0
    nullstring db '',0
.code
start:

    invoke  mciSendString, cmd_close, nullstring, 0, 0
    invoke  mciSendString, cmd_open, nullstring, 0, 0
    invoke  mciSendString, cmd_play, nullstring, 0, 0

    cinvoke printf, CRLF
    cinvoke printf, 'Press the Enter key...'
    cinvoke getchar
    invoke  ExitProcess,0

section '.idata' import data readable writeable

library kernel32,'kernel32.dll',\
     user32,  'user32.dll',\
  winmm,   'winmm.dll',\
   msvcrt,  'msvcrt.dll'

include 'api\kernel32.inc'
include 'api\user32.inc'

import winmm,\
       mciSendString, 'mciSendStringA'

import msvcrt,\
       printf, 'printf',\
       getchar,'getchar'

; end of file
    

Here is the one I made a few weeks ago
Code:
format PE GUI 4.0
include 'win32a.inc'
start:
  invoke  mciSendString, close, 0, 0
  invoke  mciSendString, opcom, 0, 0
  invoke  mciSendString, play, 0, 0
   invoke  ExitProcess, 0
section '.data' data readable writeable
 close   db   "Close Mp3",0
        opcom   db   "Open C:\test.MP3 Alias Mp3",0
  play    db   "Play C:\test.mp3 wait",0
section '.idata' import data readable writeable
  library kernel32, "KERNEL32.DLL",\
               winmm, "WINMM.DLL"
        import kernel32,\
         ExitProcess, "ExitProcess"
 import winmm,\
            mciSendString, "mciSendStringA"
    
Post 10 Jun 2011, 05:08
View user's profile Send private message Reply with quote
catafest



Joined: 05 Aug 2010
Posts: 129
catafest 18 May 2017, 18:34
I try it just run first time then the source code don't want to be compile on next change. This is strange !
see my changes:
Code:
        close   db   "Close C:\FASM\testing.Mp3",0
        opcom   db   "Open C:\FASM\testing.Mp3 Alias Mp3",0
        play    db   "Play C:\FASM\testing.Mp3 wait",0       


me239 wrote:
Hello! Today I was trying to make a mp3 player using the native mci, but haven't had much luck. Here is my code:
Code:
format PE GUI 4.0
include 'win32a.inc'
section '.code' readable executable
start:        
        invoke  mciSendString, close, 0, 0
        invoke  mciSendString, opcom, 0, 0
        invoke  mciSendString, play, 0, 0
        invoke  Sleep, -1
section '.data' data readable writeable
        close   db   "Close Mp3",0
        opcom   db   "Open C:\test.MP3 Alias Mp3",0
        play    db   "Play C:\test.mp3 from 0",0
section '.idata' import data readable writeable
        library kernel32, "KERNEL32.DLL",\
                winmm, "WINMM.DLL"
        import kernel32,\
               Sleep, "Sleep"
        import winmm,\
               mciSendString, "mciSendStringA"
    
Post 18 May 2017, 18:34
View user's profile Send private message Visit poster's website Yahoo Messenger Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20445
Location: In your JS exploiting you and your system
revolution 18 May 2017, 22:09
catafest wrote:
I try it just run first time then the source code don't want to be compile on next change. This is strange !
see my changes:
Code:
        close   db   "Close C:\FASM\testing.Mp3",0
        opcom   db   "Open C:\FASM\testing.Mp3 Alias Mp3",0
        play    db   "Play C:\FASM\testing.Mp3 wait",0       
I get this to compile:
Code:
format PE GUI 4.0
include 'win32a.inc'
section '.code' readable executable
start:
        invoke  mciSendString, close, 0, 0
        invoke  mciSendString, opcom, 0, 0
        invoke  mciSendString, play, 0, 0
        invoke  Sleep, -1
section '.data' data readable writeable
        close   db   "Close C:\FASM\testing.Mp3",0
        opcom   db   "Open C:\FASM\testing.Mp3 Alias Mp3",0
        play    db   "Play C:\FASM\testing.Mp3 wait",0
section '.idata' import data readable writeable
        library kernel32, "KERNEL32.DLL",\
                winmm, "WINMM.DLL"
        import kernel32,\
               Sleep, "Sleep"
        import winmm,\
               mciSendString, "mciSendStringA"    
What error do you get from fasm?
Post 18 May 2017, 22:09
View user's profile Send private message Visit poster's website Reply with quote
catafest



Joined: 05 Aug 2010
Posts: 129
catafest 19 May 2017, 14:35
This error , see screenshot http://imgur.com/egrgEpH
First time is compile and run well the second time I got this error .

revolution wrote:
catafest wrote:
I try it just run first time then the source code don't want to be compile on next change. This is strange !
see my changes:
Code:
        close   db   "Close C:\FASM\testing.Mp3",0
        opcom   db   "Open C:\FASM\testing.Mp3 Alias Mp3",0
        play    db   "Play C:\FASM\testing.Mp3 wait",0       
I get this to compile:
Code:
format PE GUI 4.0
include 'win32a.inc'
section '.code' readable executable
start:
        invoke  mciSendString, close, 0, 0
        invoke  mciSendString, opcom, 0, 0
        invoke  mciSendString, play, 0, 0
        invoke  Sleep, -1
section '.data' data readable writeable
        close   db   "Close C:\FASM\testing.Mp3",0
        opcom   db   "Open C:\FASM\testing.Mp3 Alias Mp3",0
        play    db   "Play C:\FASM\testing.Mp3 wait",0
section '.idata' import data readable writeable
        library kernel32, "KERNEL32.DLL",\
                winmm, "WINMM.DLL"
        import kernel32,\
               Sleep, "Sleep"
        import winmm,\
               mciSendString, "mciSendStringA"    
What error do you get from fasm?
Post 19 May 2017, 14:35
View user's profile Send private message Visit poster's website Yahoo Messenger Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20445
Location: In your JS exploiting you and your system
revolution 20 May 2017, 00:28
Write failed mean the program is still running. You will have terminate it before you can overwrite the .exe file.

Maybe use ExitProcess instead of Sleep? I haven't tried it. But unless it terminates you will always have this problem.
Post 20 May 2017, 00:28
View user's profile Send private message Visit poster's website Reply with quote
catafest



Joined: 05 Aug 2010
Posts: 129
catafest 20 May 2017, 12:05
+1 revolution
Thank you.
Yes is Sleep over FASM compile, also the task is not show into Task Manager.
revolution wrote:
Write failed mean the program is still running. You will have terminate it before you can overwrite the .exe file.

Maybe use ExitProcess instead of Sleep? I haven't tried it. But unless it terminates you will always have this problem.
Post 20 May 2017, 12:05
View user's profile Send private message Visit poster's website Yahoo Messenger Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.