Solved

Playing wav files using sndPlaySound or PlaySound

Posted on 1998-12-13
6
1,531 Views
Last Modified: 2013-11-20
This is how I did it, I used sndPlaySound(filename, SND_SYNC |SND_LOOP) or PlaySound(filename, NULL, SND_SYNC|SND_LOOP) to play a .wav file but however I got a linking error message which says "unresolved external symbol". I've also included "mmsystem.h" header file. How can I solve the problem? What's the difference between sndPlaySound and PlaySound? Is it true that PlaySound can play a .wav from a resource while sndPlaySound can't?
0
Comment
Question by:thankyouall
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 8

Expert Comment

by:Answers2000
ID: 1326135
1. Fix Unresolved external - link WINMM.LIB (to see this in help click Quick Info button when you see tha API call)

2. sndPlaySound plays a system sound (see WIN.INI or registry) or a file, PlaySound can do either or play a sound in your app's resources.  Otherwise not much difference.  There is often more than 1 way to do the same thing in Windows.

3. PlaySound can play from resource.  sndPlaySound can't.  If you look at parameters, this is obvious as sndPlay sound doesn't include an instance or module handle parameter.  Windows API functions accessing resources usually (always ?) have this as a paramter, e.g. LoadBitmap, LoadString, etc.
0
 

Author Comment

by:thankyouall
ID: 1326136
How can I link my program with WINMM.LIB?
0
 

Author Comment

by:thankyouall
ID: 1326137
okay, I've managed to link it with WINMM.LIB, the error message is gone but I still can't hear the sound. I would like to play a non-system wav sound, can it be done using sndPlaySound or PlaySound? Please help.
0
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 
LVL 8

Accepted Solution

by:
Answers2000 earned 50 total points
ID: 1326138
1. To play a .WAV file

PlaySound( "file.wav", NULL, SND_FILENAME ) ;
or
sndPlaySound( "file.wav", 0 ) ;

for file name make sure you specify the full path.  If you use \ in string literals, then make sure you escape it
e.g.
"C:\\WINDOWS\\file.wav"  in C, means "C:\WINDOWS\file.wav" in DOS


2. To play from resources

i. Insert a .wav file into your resources
- Go to resource tree on workspace
- Right click
- Pick "Import..."
- Browse the WAV file
- Assign an arbitary id, e.g. "IDC_WAVE"

ii. Play the wave file with
PlaySound( MAKEINTRESOURCE(IDC_WAVE),  AfxGetResourceHandle(), SND_RESOURCE ) ;

0
 

Author Comment

by:thankyouall
ID: 1326139
Okie thanks... I'll try it out! :)
0
 

Author Comment

by:thankyouall
ID: 1326140
It works! Thanks for your help!
0

Featured Post

Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

617 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