Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PlaySound api doesn't work 3

Status
Not open for further replies.

OrthoDocSoft

Programmer
May 7, 2004
291
US
Folks,

I'm using the Playsound api call and it works fine on my development computer (running XP). When I intall in in my client computer (running 2000 professional, I think): no sound. I looked for registrations and components that might be missing in the compile, but nothing was clear. Any thoughts?

(here's the api)
Code:
Public Declare Function PlaySound Lib "winmm.dll" _
Alias "PlaySoundA" (ByVal lpszName As String, _
ByVal hModule As Long, ByVal dwFlags As Long) As Long

Thanks,

Ortho

[lookaround] "you cain't fix 'stupid'...
 
OK, just for fun let's try using a slightly different API call from winmm.dll

Declare Function sndPlaySound32 Lib "winmm.dll" Alias "sndPlaySoundA"
(ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

sndPlaySound32 strAppPathway, 0
 
And a question: are you trying to play the same sound file on the development machine as on the client machine?
 
>running 2000 professional

I Have this notation for Vista compatibility in my notes:
"If you are using the PlaySound API, if your wave files are not PCM but mpeg layer-3 make sure your mpeg wave files are Stereo and not Mono."

Is this an issue with 2000 professional?
 
strongm,

Your new code works at home. Clientworld tomorrow....

Ortho

[lookaround] "you cain't fix 'stupid'...
 
strongm,

Alas, it did not work in client world. Do you or anyone have any other ideas?

Sadly,

Ortho

[lookaround] "you cain't fix 'stupid'...
 
Should I try replacing winmm.dll? I tried simply deleting it and downloading a new one, but I got the error "Cannot delete. dll in use by Windows."

Ortho

[lookaround] "you cain't fix 'stupid'...
 
I don't suspect anything wrong with the DLL. However, if you really want to verify its integrity, just zip the DLL, check its CRC32, and compare it with that of replacement DLL which is known to be healthy. Make sure both DLLs have same version number. Mine turns out to be version 5.1.2600.2180 with CRC32=0x123646FA on WinXP Pro SP2.

I can't reproduce the problem you are facing. The sound just plays fine. May be you need to check your service pack or check the code on some other machine.

Lastly, I would like to introduce you to another variation of PlaySound function which works with embedded sounds and is easier than three57m's method.

PlaySound function supports SND_RESOURCE flag which advises the function to interpret the lpszName parameter directly as a resource identifier holding the wave sound. PlaySound then loads the resource and plays it by itself. You don't have to worry about loading resource data or Dim/Static issues.

See how it goes. (Assuming you have embedded the sounds exactly the same way as advised by three57m in his first post above).
___
[tt]
Private Declare Function PlaySound Lib "winmm" Alias "PlaySoundA" (ByRef lpszName As Any, ByVal hModule As Long, ByVal dwFlags As Long) As Long
Const SND_ASYNC = &H1
Const SND_RESOURCE = &H40004

Private Sub Command1_Click()
PlaySound ByVal 101&, App.hInstance, SND_ASYNC Or SND_RESOURCE '101=Resource Identifier
End Sub[/tt]
___

Note that this code will not work in IDE. You have to make EXE to test it. The reason is that PlaySound is an API function which always tries to locate the sound in the resource section of the running process, which is VB6.EXE in case of IDE.

VB's LoadResData function, on the other hand, is smart enough to look for the data in the resource file when in IDE, and application's own resource when running from EXE.
 
First, Hypetia, thank you for your attempt to yet solve this perplexing problem.

Second, and please don't hate me; this morning in clientworld, ALL of your codes work, including my original one! I really didn't do anyting new. Isn't that weird? If nothing else, this thread will serve as a tutorial for others. I DO appreciate all of you.

Stars for you.

Ortho

[lookaround] "you cain't fix 'stupid'...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top