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
Solved

getting winmm.lib with PlaySound into the project settings

Posted on 1998-10-28
3
520 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Whole sheet autoscrub still needed 19 51
Annoying "thing" blocks my view 4 114
Way to decrease size of apk file 9 86
I could not set window to top 4 20
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

809 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