flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Windows > mciSendString

Author
Thread Post new topic Reply to topic
me239



Joined: 06 Jan 2011
Posts: 207
mciSendString
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  mciSendStringclose00
        invoke  mciSendStringopcom00
        invoke  mciSendStringplay00
        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
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
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: 207

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

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
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: 207
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
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: 207
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: 207
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
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  mciSendStringcmd_closenullstring00
    invoke  mciSendStringcmd_opennullstring00
    invoke  mciSendStringcmd_playnullstring00

    cinvoke printfCRLF
    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: 207

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  mciSendStringcmd_closenullstring00
    invoke  mciSendStringcmd_opennullstring00
    invoke  mciSendStringcmd_playnullstring00

    cinvoke printfCRLF
    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  mciSendStringclose00
  invoke  mciSendStringopcom00
  invoke  mciSendStringplay00
   invoke  ExitProcess0
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: 78
Re: mciSendString
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  mciSendStringclose00
        invoke  mciSendStringopcom00
        invoke  mciSendStringplay00
        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 Yahoo Messenger Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14673
Location: Origae-6
Re: mciSendString

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  mciSendStringclose00
        invoke  mciSendStringopcom00
        invoke  mciSendStringplay00
        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: 78
Re: mciSendString
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  mciSendStringclose00
        invoke  mciSendStringopcom00
        invoke  mciSendStringplay00
        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 Yahoo Messenger Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14673
Location: Origae-6
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: 78
+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 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


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.