Posted on 2000-02-09
Medium Priority
Last Modified: 2010-05-02
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?
Question by:crazyman
  • 3
  • 2

Expert Comment

ID: 2504615
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!


LVL 13

Author Comment

ID: 2504636
That works fine but...i cant distribute the wav files with the ocx thats why i wanted the data from the .res file

Accepted Solution

MTroutwine earned 200 total points
ID: 2504725
Sorry about that here is Microsoft's solution:

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

LVL 13

Author Comment

ID: 2506915
That link doesnt work for me...?
LVL 13

Author Comment

ID: 2507089
Cheers i serched for thast article on ms kb

Works great ..thanks!

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

593 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question