How do i use the playsound api to play a wav file from a .res file.

I tried using PlaySound loadresdata(101,10),0,0 but i always get that element 101 doesnt exist when i know it does...
Any ideas?
LVL 13
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Try this, to test it add a button to a form and then paste this code in the form:

Option Explicit

Private Const SND_NODEFAULT = &H2
Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

Private Sub Command1_Click()
    PlayWav LoadResString(101)
End Sub

Public Sub PlayWav(ByVal WavFilePath As String)
    ' ----------------------------------
    ' Local Variable Declarations:
    ' ----------------------------------
    Dim lngReturn As Long
    ' If the path length is 0 exit:
    If Len(Dir(Trim(WavFilePath))) = 0 Then
        Exit Sub
    End If
    ' Play the wav file:
    lngReturn = sndPlaySound(WavFilePath, SND_NODEFAULT)
End Sub

In the Resource editor add a string value that contains the path to the wave file!


crazymanAuthor Commented:
That works fine but...i cant distribute the wav files with the ocx thats why i wanted the data from the .res file
Sorry about that here is Microsoft's solution:

Article ID: Q141505
Title: "Using LoadResData with Binary Data"


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
crazymanAuthor Commented:
That link doesnt work for me...?
crazymanAuthor Commented:
Cheers i serched for thast article on ms kb

Works great ..thanks!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.