Solved

getting winmm.lib with PlaySound into the project settings

Posted on 1998-10-28
3
511 Views
Last Modified: 2013-11-20
I'm trying to play a wav file with PlaySound and include <mmsystem.h>.  The build fails at the link with the following message:

error LNK2001: unresolved external symbol __imp__PlaySoundA@12

I tried to add winmm.lib to the project settings, but must be doing it incorrectly.  What changes do I need to make to the project settings?
0
Comment
Question by:Ashurbanipal
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
stefanr earned 50 total points
Comment Utility
The easiest way of including a lib file is to tell it directly in the source code (for Visual C++), as below:

#include <mmsystem.h>

#pragma comment(lib, "winmm.lib")

We have done this a number of times (including this particular files), and it has never failed.

Hope this helps.
0
 

Author Comment

by:Ashurbanipal
Comment Utility
I already had the following line at the top of the .cpp file:

#include <mmsystem.h>

Without that the file generates errors because it doesn't recognize PlaySound.  The error occurs while linking, that is why it must have something to do with the project settings.
0
 
LVL 3

Expert Comment

by:stefanr
Comment Utility
the

#pragma comment(lib, "winmm.lib")

is used at link time to link to the .lib file in question. Therefore you shouldn't get any linking errors if you add this line in your cpp file (unless somehow the LIB-path is not set properly; see your environment in a console window using the SET command). You could also add the winmm.lib in the Project Settings/Link/Object+Library modules, but in that case you have to do it every time you use the same source files in new projects. It's easier to use #pragma comment(lib, "...").

If your LIB path in the console window lacks the paths similar to
c:\program\devstudio\vc\lib;c:\program\devstudio\vc\mfc\lib
you have to add them using (in NT) the Control Panel/System/Environment. I'm not sure about Windows 95/98, but maybe you have to edit the autoexec.bat file to add this environment variable.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now