Solved

getting winmm.lib with PlaySound into the project settings

Posted on 1998-10-28
3
513 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
ID: 1323956
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
ID: 1323957
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
ID: 1323958
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

914 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

21 Experts available now in Live!

Get 1:1 Help Now