Results 1 to 13 of 13

Thread: sndPlaySound QUICKIE!

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2002
    Location
    I'll kick yo' @$$!!
    Posts
    44

    sndPlaySound QUICKIE!

    Ok, so I try using the sndPlaySound to play a WAV file, and no matter what I do it doesn't work. Here's what I did.

    First, and most obvious, I declared the function. 'Tis in a module. Hehe, i said "tis". Anyway, there's nothing worng with it, but just to rehash,
    VB Code:
    1. Public Declare Function sndPlaySound _
    2.   Lib "winmm.dll" (ByVal lpszSoundName As String, _
    3.   ByVal uFlags As Long) As Long
    4.  
    5. Public Const SND_SYNC = &H0
    6. Public Const SND_ASYNC = &H1
    K. So there's what I have down in the module. Here is the code I have to play the sound file:
    VB Code:
    1. sndPlaySound "shot1.wav", SND_ASYNC
    It's in an If statement, nothing's wrong with the If statement. No matter what I do, whether it be getting rid of that flag or using a different flag, this is what I get:

    Can't find DLL entry point sndPlaySound in winmm.dll

    So, it doesn't work. What am I doing wrong? Other peoples' projects with sound work, but mine doesn't, and I don't see what's so special about it. HELP!!

  2. #2
    Lively Member
    Join Date
    Mar 2001
    Location
    Graduate Office (aka "Pit of Despair")
    Posts
    88
    I've never added sound to my projects, however I noticed this on the vbapi.com website (http://216.26.161.91/vbapi/ref/s/sndplaysound.html)

    NOTE: The function sndPlaySound is obsolete. It is superseded by the PlaySound function.
    Er, perhaps looking at PlaySound would be best?
    - Kronix


    "I have not failed. I have merely found 10,000 ways that won't work." - Thomas Edison

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2002
    Location
    I'll kick yo' @$$!!
    Posts
    44
    well i guess i should use the latest function or whatever, but i cant get that one working either! it either says 'argument not optional', or 'type mismatch'. Bah. Can someone tell me the easiest way to just play a sound??

  4. #4
    Fanatic Member McCain's Avatar
    Join Date
    Jan 2002
    Location
    Sweden/Denmark
    Posts
    802
    from www.allapi.net...
    You need

    VB Code:
    1. Public Const SND_FILENAME = &H20000     ' name is a file name
    And then
    VB Code:
    1. PlaySound "C:\WINDOWS\MEDIA\TADA.WAV", ByVal 0&, SND_FILENAME Or SND_ASYNC
    Never argue with fools, they will only drag you down to their level, and beat you with experience.

    Q: How do you tell an experienced hacker from a novice?
    A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer

  5. #5

    Thread Starter
    Member
    Join Date
    Apr 2002
    Location
    I'll kick yo' @$$!!
    Posts
    44
    Didn't work. First of all, the function that
    I got was called PlaySound_Res, but was also referred to just as PlaySound. There was an alias of PlaySoundA. Does this sound right so far? K, now here's what I did:
    VB Code:
    1. PlaySound_Res "shot1.wav", ByVal 0&, SND_FILENAME Or SND_ASYNC
    See, if i just used PlaySound instead of PlaySound_Res, it wouldnt do anything, it said 'sub or function not defined'. So using that bit of code above, I get an error of 'Type Mismatch'. WHY AM I HAVING SO MUCH TROUBLE WITH SOUND?? Anybody got any ideas why this isnt working either?
    XX The Signature of the Gods XX

  6. #6

    Thread Starter
    Member
    Join Date
    Apr 2002
    Location
    I'll kick yo' @$$!!
    Posts
    44
    OK, I got the right function now, its not PlaySound_Res, I got the PlaySound one. And I got it to work, using
    VB Code:
    1. PlaySound app.path & "\sounds\shot1.wav", ByVal 0&, SND_FILENAME Or SND_ASYNC
    Now, though, could you (or someone) explain what the "ByVal 0&, SND_FILENAME Or SND_ASYNC" part of that means? I'd appreciate it.
    XX The Signature of the Gods XX

  7. #7
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    ByVal 0& is just the handle to the executable file that contains the resource to be loaded. You can set it to 0 or vbNullString if you don't want to load the sound file from a resource. If you do want to, you'll have to provide the flag "SND_RESOURCE" in the next parameter.

    SND_FILENAME Or SND_ASYNC are just flags that you provide the the function. SND_FILENAME tells the function that you want to play the sound by providing it a filename. SND_ASYNC play the sounds asynchronously. The function is returned immediately after the function is called.
    Baaaaaaaaah

  8. #8

    Thread Starter
    Member
    Join Date
    Apr 2002
    Location
    I'll kick yo' @$$!!
    Posts
    44
    ByVal 0& is just the handle to the executable file that contains the resource to be loaded. You can set it to 0 or vbNullString if you don't want to load the sound file from a resource. If you do want to, you'll have to provide the flag "SND_RESOURCE" in the next parameter.
    K. what do you mean by resource? and the executable file you're talking about, is that the one that is made of that project?

    And "If I want to, I'll have to provide SND_RESOURCE in the next paramater." what's that mean?

    I switched ByVal 0& to just plain 0, and I see no difference whatsoever. I didn't include any SND_RESOURCE either. BTW when I declare the SND_RESOURCE const, uhh, what's the value?
    XX The Signature of the Gods XX

  9. #9
    Fanatic Member McCain's Avatar
    Join Date
    Jan 2002
    Location
    Sweden/Denmark
    Posts
    802
    You only have to worry about snd_resource if you have the file you want to play in a resource-file... If you don't know what a resource file is you don't have to worry =) Or you could use google.com to find out...
    Never argue with fools, they will only drag you down to their level, and beat you with experience.

    Q: How do you tell an experienced hacker from a novice?
    A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer

  10. #10

    Thread Starter
    Member
    Join Date
    Apr 2002
    Location
    I'll kick yo' @$$!!
    Posts
    44
    okies thnx!
    XX The Signature of the Gods XX

  11. #11
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    ma,usa
    Posts
    485

    How can I fix this code to play 2 sounds at once?

    How can I fix the previous code to play 2 sounds at once?

  12. #12
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    For that, you'll have to use the old W3.1 "Wavemix.dll" or go for DirectSound, I believe. Though I've only used sndPlaySound, not just PlaySound. Maybe it can do that already.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  13. #13
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    ma,usa
    Posts
    485

    HELP,HELP,HELP!

    Anyone have a step by step on this? I did a search but everything came up as C++ code and tutorials. Also I could not make the "make" files work so I could even attempt a translation. The API's needed were not in my api viewer but yet the samples of precompiled exe's worked. PLEASE,PLEASE HELP!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width