|
-
Apr 26th, 2002, 04:52 PM
#1
Thread Starter
Member
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:
Public Declare Function sndPlaySound _
Lib "winmm.dll" (ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long
Public Const SND_SYNC = &H0
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:
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!!
-
Apr 26th, 2002, 05:00 PM
#2
Lively Member
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
-
Apr 26th, 2002, 10:12 PM
#3
Thread Starter
Member
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??
-
Apr 27th, 2002, 01:45 AM
#4
Fanatic Member
from www.allapi.net...
You need
VB Code:
Public Const SND_FILENAME = &H20000 ' name is a file name
And then
VB Code:
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
-
Apr 27th, 2002, 09:13 AM
#5
Thread Starter
Member
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:
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
-
Apr 27th, 2002, 09:36 AM
#6
Thread Starter
Member
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:
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
-
Apr 27th, 2002, 11:04 AM
#7
PowerPoster
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.
-
Apr 28th, 2002, 03:57 PM
#8
Thread Starter
Member
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
-
Apr 28th, 2002, 04:00 PM
#9
Fanatic Member
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
-
Apr 28th, 2002, 04:06 PM
#10
Thread Starter
Member
XX The Signature of the Gods XX
-
Apr 29th, 2002, 11:47 AM
#11
Hyperactive Member
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?
-
Apr 29th, 2002, 02:52 PM
#12
Good Ol' Platypus
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)
-
May 3rd, 2002, 10:37 AM
#13
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|