Announcement

Collapse
No announcement yet.

Can you play a WAV file in PBDOS by a SHELL to a PBCC program?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can you play a WAV file in PBDOS by a SHELL to a PBCC program?

    On my system, program 1 works fine if it is run in PBCC, but if it's run in PBDOS the only output is a "bad command or file name" error message.
    If there is a way to correct the error, please let me know.

    '===================================================
    'Program 1: Run this in PBDOS &/or compile it & run it in PBCC

    CALL PBMAIN 'delete or REM-out this line for PBCC
    SUB PBMAIN
    SHELL "PLAYSOUND.EXE"
    END SUB
    '===================================================
    'Program 2: Compile this in PBCC as PLAYSOUND.EXE

    'PLAYSOUND
    'by Mike Doty, PB Forums, 2009
    'for PBCC
    DECLARE FUNCTION PlaySound LIB "WINMM.DLL" ALIAS "PlaySoundA" (lpszName AS ASCIIZ, _
    BYVAL hModule AS DWORD, BYVAL dwFlags AS DWORD) AS LONG

    %NULL = 0
    %SND_SYNC = &H0 ' play synchronously (default)
    %SND_ASYNC = &H1 ' play asynchronously

    FUNCTION PBMAIN () AS LONG
    Play ""
    SLEEP 3000 ' %SND_ASYNC if ASYNC
    END FUNCTION

    SUB Play(sFileName AS STRING) EXPORT
    LOCAL zFileName AS ASCIIZ * 128
    IF LEN(sFileName) = 0 THEN sFileName = "tada"
    zFileName = sFileName + $NUL
    CALL PlaySound(zFileName, %NULL ,%SND_ASYNC) 'use sync so sound file completes
    END SUB

  • #2
    but if it's run in PBDOS the only output is a "bad command or file name" error message.
    If there is a way to correct the error, please let me know
    Your MS-DOS program cannot find the PLAYSOUND.EXE file named in the SHELL line.

    You are probably in the wrong directory when you run the program. See CURDIR$ (I think that's in PB-DOS).
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      >>Your MS-DOS program cannot find the PLAYSOUND.EXE file named in the SHELL line.

      I don't think that's it. Thus, for example, if Program 2 PLAYSOUND.BAS were to read
      SUB PBMAIN()
      PRINT "Hello world"
      END SUB

      there is no problem.
      Also, the problem occurs even when both PLAYSOUND.EXE and the .WAV file to be played can be recognized as present by DIR$.
      Last edited by Emil Menzel; 1 Jul 2009, 11:55 AM.

      Comment


      • #4
        Does fully qualifying the path work?
        Example: SHELL ("C:\FOLDER\PLAYSOUND.EXE")

        If not, the command processor might be needed in the shell.

        PBCC method (not sure how to do this with DOS program.)
        SHELL ENVIRON$("COMSPEC") + " /C DIR *.* > filename.txt"
        Last edited by Mike Doty; 1 Jul 2009, 12:12 PM.
        The world is full of apathy, but who cares?

        Comment


        • #5
          "Bad Command or Filename" is recognizable by anyone who ever spent any time using (REAL) MS-DOS.

          It's been replaced in the Win/XP command shell CMD.EXE with
          Code:
          C:\Documents and Settings\Michael>askdas
          'askdas' is not recognized as an internal or external command,
          operable program or batch file.
          
          C:\Documents and Settings\Michael>
          Operating systen not specified.

          MCM
          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            Emil,
            I tried shelling from a PDS 7.1 program and get the same error.
            Thinking ...
            The world is full of apathy, but who cares?

            Comment


            • #7
              SHELL "cmd.exe /c playsound.exe" (works with XP)

              As Michael mentioned the operating system should be checked to see which command processor to use in the shell.
              Last edited by Mike Doty; 1 Jul 2009, 12:35 PM.
              The world is full of apathy, but who cares?

              Comment


              • #8
                Thank you!

                P.S. I've only been working with MS-DOS since the days of DOS 2.0, so I must still be a "newbie".

                Comment


                • #9
                  The good news is that the PBDOS SHELL can play the WAV file; the bad news is on my graphics-screen program, it badly messes up the graphics display. Hopefully there's a fix for that too.

                  Comment


                  • #10
                    Just curious. Have you tried searching for "native" DOS based code for a playwave function? I'm sure that there has to be one around somewhere.
                    Scott Slater
                    Summit Computer Networks, Inc.
                    www.summitcn.com

                    Comment


                    • #11
                      At a command prompt:
                      cmd /? > me.txt
                      notepad me.txt
                      Hopefully one of the switches.
                      The world is full of apathy, but who cares?

                      Comment


                      • #12
                        Scott:
                        I have found QB and PBDOS programs that will play a WAV file, but they have problems of their own -- e.g., they cannot play synchronously.

                        Mike:
                        Thanks again

                        Comment


                        • #13
                          Did a switch fix the problem?
                          If not, maybe a shell to another program that shells to playsound.
                          The world is full of apathy, but who cares?

                          Comment


                          • #14
                            Mike: No luck so far.
                            I could always copy the graphics screen before SHELLing, and refresh it afterwards, but my program is a graphics game program & I'm trying to get it to "click" up to at least 15 times a second (whenever mouse or joystick motion is detected). Fifteen SHELLs per sec sounds unlikely, but 15 graphics screen copies & refreshes on top of that sounds wild.

                            Coincidentally, none of the DOS joystick drivers I have used function anymore in PBDOS when it is run under Windows XP. (Haven't tried Vista or Windows 7, but my hopes for them would not be high). Fortunately, that problem can be whipped with the shareware program "Total Game Control" (about $20) or the freeware program "JOYCUR.BAS", and doubtless others as well.
                            Last edited by Emil Menzel; 2 Jul 2009, 07:20 AM.

                            Comment


                            • #15
                              A background PBCC program could be loaded with the
                              PBDos program. If the PBDos program creates an
                              event the background PBCC program could playsound
                              without the need to shell.
                              The world is full of apathy, but who cares?

                              Comment


                              • #16
                                Code:
                                #COMPILE EXE  'monitor.bas
                                #DIM ALL
                                #INCLUDE "win32api.inc"
                                GLOBAL gDirectoryToWatch AS ASCIIZ * 64
                                GLOBAL gExitTimeout AS LONG
                                $FileName = "c:\junk.txt"
                                FUNCTION PBMAIN AS LONG
                                  LOCAL hThread???, var&, h&, x&, lResult&
                                  gDirectoryToWatch  = "c:\"
                                  gExitTimeout = 3000   'check for exit every 3-seconds
                                  THREAD CREATE WatchDirectory(var&) TO hThread???
                                  THREAD CLOSE hThread TO lResult
                                  DO:    SLEEP 1000:  LOOP WHILE THREADCOUNT > 1
                                END FUNCTION
                                FUNCTION WatchDirectory (BYVAL x AS LONG) AS LONG
                                  LOCAL lDir AS DWORD, found AS DWORD
                                  DO
                                    'lDir = FindFirstChangeNotification(gDirectoryToWatch, 0, %FILE_NOTIFY_CHANGE_SIZE)
                                    lDir = FindFirstChangeNotification(gDirectoryToWatch, 0, %FILE_NOTIFY_CHANGE_LAST_WRITE)
                                    Found = WaitForSingleObject(lDir, gExitTimeout)
                                    IF found = 0 THEN  CALL PlaySound("tada", %NULL ,%SND_ASYNC)
                                    FindCloseChangeNotification(lDir)
                                  LOOP WHILE ISFILE($FileName)
                                END FUNCTION
                                Code:
                                 
                                  CLS
                                  sFile$ = "c:\junk.txt"
                                  h = FREEFILE
                                  OPEN sFile$ FOR OUTPUT AS #h
                                  CLOSE #h
                                  DO
                                    PRINT "DosPgm press a key to open file or ESC to exit"
                                    x$ = INPUT$(1)
                                    IF x$ = CHR$(27) THEN EXIT DO
                                    h = FREEFILE
                                    OPEN sFile$ FOR OUTPUT AS #h
                                    CLOSE #h
                                  LOOP
                                  KILL sFile$
                                The world is full of apathy, but who cares?

                                Comment


                                • #17
                                  have found QB and PBDOS programs that will play a WAV file, but they have problems of their own -- e.g., they cannot play synchronously
                                  ???

                                  They launch another program and return immediately? Sounds like you can cut out the middlemand and launch it yourself.

                                  If you want it ASNYCHRONOUSLY (SHELL returns immediately and music plays in background), from your DOS program you can "SHELL START playsound.exe" and that's what will happen.
                                  Michael Mattias
                                  Tal Systems (retired)
                                  Port Washington WI USA
                                  [email protected]
                                  http://www.talsystems.com

                                  Comment


                                  • #18
                                    Michael:
                                    I got sync & async confused. Thank you for setting that straight, and for the other tips.

                                    Mike:
                                    Your "No SHELL, PBCC in the background" solution looks good. In fact, it might be tweaked to solve the joystick problem too!

                                    Comment


                                    • #19
                                      PLAYSOUND.EXE is more than 8 chars before the extension.
                                      (8.3)
                                      hellobasic

                                      Comment


                                      • #20
                                        A windows program could start the DOS program.
                                        This windows program would eliminate the DOS shell and could also read commands to execute from the DOS program.
                                        Code:
                                        #COMPILE EXE  'monitor.bas
                                        #DIM ALL
                                        #INCLUDE "win32api.inc"
                                        GLOBAL gDirectoryToWatch AS ASCIIZ * 64
                                        GLOBAL gExitTimeout AS LONG
                                        $FileName = "c:\folder\change\monitor.txt"
                                         
                                        FUNCTION PBMAIN AS LONG
                                          LOCAL hThread???,  h&, x&, lResult&
                                         
                                          lRESULT = SHELL("DOSPGM") 'start dos program
                                          gDirectoryToWatch  = "c:\"
                                          gExitTimeout = 3000   'check for exit every 3-seconds
                                          THREAD CREATE WatchDirectory(x) TO hThread???
                                          THREAD CLOSE hThread TO lResult
                                          DO:    SLEEP 1000:  LOOP WHILE THREADCOUNT > 1
                                          ? "Monitor ended"
                                        END FUNCTION
                                        FUNCTION WatchDirectory (BYVAL x AS LONG) AS LONG
                                          LOCAL lDir AS DWORD, found AS DWORD
                                          DO
                                            'lDir = FindFirstChangeNotification(gDirectoryToWatch, 0, %FILE_NOTIFY_CHANGE_SIZE)
                                            lDir = FindFirstChangeNotification(gDirectoryToWatch, 0, %FILE_NOTIFY_CHANGE_LAST_WRITE)
                                            Found = WaitForSingleObject(lDir, gExitTimeout)
                                            IF found = 0 THEN  CALL PlaySound("tada", %NULL ,%SND_ASYNC)
                                            FindCloseChangeNotification(lDir)
                                          LOOP WHILE ISFILE($FileName)
                                        END FUNCTION
                                        Last edited by Mike Doty; 2 Jul 2009, 12:48 PM.
                                        The world is full of apathy, but who cares?

                                        Comment

                                        Working...
                                        X