Solved

getting winmm.lib with PlaySound into the project settings

Posted on 1998-10-28
3
526 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
[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
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

705 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