Announcement

Collapse

Maintenance

The forum could be offline for 30-60 minutes in the very near future for maintenance (said 3pm Pacific). I was behind on getting this notice. I do apologize.
See more
See less

I like to play sound from my resource file

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

  • I like to play sound from my resource file

    Hello.

    I have attached the following line to my RC file.

    MYSOUND SOUND SOUND.WAV

    How can i play this resource file with i.e. PlaySound.....?

    Thank you...Michael

    ------------------

  • #2
    Try this:
    Code:
    CALL PlaySound("MYSOUND", BYVAL GetModuleHandle(BYVAL %NULL), %SND_RESOURCE OR %SND_SYNC)

    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Lance
    mailto:[email protected]

    Comment


    • #3
      Hello Lance.

      Many thanks for your help.

      I have checked over and over your example but (although compilation is successful) it doesn' t work for any reason.

      If I use the simple:

      PlaySound "SOUND.WAV", 0, %SND_SYNC

      it works but I like to have it played from the resource file.
      ------------------
      Michael


      ------------------

      Comment


      • #4
        Is there anything else in your resource file or just this WAV file?


        ------------------
        Lance
        PowerBASIC Support
        mailto:[email protected][email protected]</A>
        Lance
        mailto:[email protected]

        Comment


        • #5
          Old PbRes, which saw first multimedia file only ?

          ------------------
          E-MAIL: [email protected]

          Comment


          • #6
            Thats is what I suspect... hence my question on the content of the resource file.

            ------------------
            Lance
            PowerBASIC Support
            mailto:[email protected][email protected]</A>
            Lance
            mailto:[email protected]

            Comment


            • #7
              Hello Lance and Semen.

              My RC-file includes the MainDialog with some controls, MainMenu, one Icon and a little bitmap.

              Now I have removed anything but the MainDialog without controls but it doesn't work too.

              Do I have to define/declare "MYSOUND" anyway ??? or is Semen right because I am still using PBDLL 5.0

              ------------------
              Thank you..Michael


              ------------------

              Comment


              • #8
                Perhaps you are running into a problem that I had. THat is,
                in a sub-folder (pbdll\rc) the rc file was and when compiled out
                to the .pbr file, that stayed in the rc file and my code looked
                for it in the \pbdll folder. The new statements, of course, were
                not in there. Correcting that oversight made everything work.

                Then again, perhaps you don't make silly little mistakes like
                I do.;-)



                ------------------
                Barry

                Comment


                • #9
                  Michael, are you writing this in a DLL or an EXE? The module handle has to be handled differently in the case of a DLL, since the module handle of the DLL will be different to that of the EXE.

                  At this point, you really need to show us exactly what your code and your RC file contains, or we'll just waste time guessing at solutions...


                  ------------------
                  Lance
                  PowerBASIC Support
                  mailto:[email protected][email protected]</A>
                  Lance
                  mailto:[email protected]

                  Comment


                  • #10
                    Michael --
                    test http://ltr.virtualave.net/sound.zip on your PC

                    [This message has been edited by Semen Matusovski (edited December 11, 2000).]

                    Comment


                    • #11
                      Hope this helps, use it dynamically with all of your sounds, I have 16 in one of my projects..


                      You could use varptr or strptr instead of the way I do it, but it does work..
                      Code:
                      '----------------------------------------------------------------------------------------
                      Function PlayWavFromResource(hInstance As Long, WaveName As String, WaveType As String)Export As Long
                      Local hRes As Long
                      Local lpWav As Byte Ptr
                      Local Wave1 As Asciiz * 10
                      Local Wav1 As Asciiz * 10
                      Wave1 = WaveName
                      Wav1  = WaveType
                      hRes = FindResource (hInstance, Wave1, Wav1)
                      If hRes Then
                          lpWav = LockResource (LoadResource (hInstance, hRes))
                          If lpWav Then Function = PlaySound(ByVal lpWav, hInstance, %SND_MEMORY Or %SND_ASYNC)
                      End If
                      End Function
                      
                      '-----------------------------------------------------------------------------------
                      ------------------
                      Scott
                      mailto:[email protected][email protected]</A>

                      [This message has been edited by Scott Turchin (edited December 11, 2000).]
                      Scott Turchin
                      MCSE, MCP+I
                      http://www.tngbbs.com
                      ----------------------
                      True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                      Comment


                      • #12
                        One thing I've noticed, and it's weird and unexplainable, but when you declare your various objects in the resource file, LOAD them in the same order...
                        ie
                        #define MYBITMAP = 1024
                        #define MYICON = 1025

                        MYBITMAP BITMAP "BITMAP.BMP"
                        MYICON ICON "ICON.ICO"

                        Then declare them again in the .BAS file in the same order, makes no sense but it's been the only way to explain it...

                        Scott

                        ------------------
                        Scott
                        mailto:[email protected][email protected]</A>

                        [This message has been edited by Scott Turchin (edited December 11, 2000).]
                        Scott Turchin
                        MCSE, MCP+I
                        http://www.tngbbs.com
                        ----------------------
                        True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                        Comment


                        • #13
                          Hello.
                          Thank you all for trying to help.

                          Here is my RC-FILE:
                          ---------------------------------------------------------------------------------
                          #include "winapi\resource.h"
                          #define MainDialog 100
                          #define IDK_START 101

                          MainDialog DIALOG 10, 10, 430, 286
                          STYLE DS_MODALFRAME | WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION |
                          WS_SYSMENU | WS_THICKFRAME
                          CAPTION " SOUNDTEST "
                          FONT 8, "MS Sans Serif"
                          CLASS "MyClass"
                          BEGIN
                          CONTROL "&Start", IDK_START, "Button", WS_TABSTOP, 2, 4, 30, 13
                          END

                          MYSOUND SOUND SOUND.WAV
                          -----------------------------------------------------------------------------------

                          And here is the part of my BAS-FILE compiled to EXE !
                          -----------------------------------------------------------------------------------

                          PlaySound("MYSOUND", BYVAL GetModuleHandle(BYVAL %NULL), %SND_RESOURCE OR %SND_SYNC)

                          If I use:
                          PlaySound "SOUND.WAV", 0, %SND_SYNC
                          it works fine.
                          -----------------------------------------------------------------------------------

                          Scott.
                          I have not defined my icon and my bitmap but it works fine.
                          What is the "WaveType"

                          -----------
                          Michael

                          ------------------

                          Comment


                          • #14
                            I'm not 100% understanding of This stuff, this is what works.

                            Also I might suggest you put the WAVE file before your dialog, should it matter? No, but it does in some cases, which was the point I was trying to make

                            But here's what works for me:


                            Resource file:

                            WAVE1 WAV01 "AIRNUKE.WAV"
                            WAVE2 WAV02 "PING.WAV"
                            WAVE3 WAV03 "RESPONSE.WAV"


                            NO declaration for the wave file, I'm not sure if one is a label and one is a name...

                            Anyway the .BAS file:
                            Code:
                            WAVE = "WAVE"
                            WAV  = "WAV"
                            
                                Case %WM_INITDIALOG
                                    g_Result = PlayWavFromResource(g_hInst,WAVE + "1",WAV + "01")
                            
                            
                            '
                            '
                            '
                            ------------------
                            Scott
                            mailto:[email protected][email protected]</A>
                            Scott Turchin
                            MCSE, MCP+I
                            http://www.tngbbs.com
                            ----------------------
                            True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                            Comment


                            • #15
                              Hello Scott.

                              Thank you for your example.
                              In this method you are loading the resource into the memory and then plays it from there.
                              I am sure it must be possible to play it direct from the resource without loading to memory.

                              Now I have discoverd that the PB.RES file includes my SOUND.WAV file... but it is definitely not in the PB.PBR file !!!

                              So that's why your example couldn't work either.

                              What could be the reason ???
                              If the SOUND.WAV file is in the PB.Res file but not after converting in the PB.PBR file..
                              There must be a bug in my PBRES.EXE version ???

                              ---------
                              Michael


                              ------------------




                              [This message has been edited by Michael Rosner (edited December 12, 2000).]

                              Comment


                              • #16
                                That's one of those funky little issues I've come across.
                                If you like, send me your resource file and wave files and all appropriate files to compile it and I will test it here, K?


                                [email protected]

                                Scott


                                ------------------
                                Scott
                                mailto:[email protected][email protected]</A>
                                Scott Turchin
                                MCSE, MCP+I
                                http://www.tngbbs.com
                                ----------------------
                                True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                                Comment


                                • #17
                                  Try using the latest version of PBRES which can be downloaded from the FILES section of the PB web site at www.powerbasic.com/files/pub


                                  ------------------
                                  Lance
                                  PowerBASIC Support
                                  mailto:[email protected][email protected]</A>
                                  Lance
                                  mailto:[email protected]

                                  Comment


                                  • #18
                                    Hello.

                                    I just like to say thank you to all for the great help.
                                    In my case it was the too old version of my PBRES.EXE

                                    The example from Lance works fine now!
                                    Semen.
                                    I don't know why but I have just overseen your link.
                                    Now i have download your file and everthing works fine.

                                    Thanks again...Michael


                                    ------------------

                                    Comment

                                    Working...
                                    X