Question

I'm using windows 7 running visual studio 2010 and writing in Cc.

Here is a snippet of my code. When the condition is met (temperature is higher than high limit) then I want to play a wav file from my computer. I checked around the forums and I copied the same format as a previous poster had i still have the same problem. I get the following errors:

1>lab4TemperatureController.obj : error LNK2019: unresolved external symbol _imp_PlaySoundA@12 referenced in function "void __cdecl activateAlarm(int,int)" (?activateAlarm@@YAXHH@Z)

1>C:\Users\Hassman\Documents\Visual Studio 2010\Projects\lab6\lab6TemperatureControlTime\Debug\lab3temperaturesensor.exe : fatal error LNK1120: 1 unresolved externals

Here are my header files included in my CPP

#include "stdafx.h"
#include "lab4temperatureController.h"
#include <conio.h>
#include "console.h"
#include <iostream>
#include <Windows.h>

here is my function that calls playsound

void activateAlarm(int channelID, temperature_t temperature)
{
    int key = 0;

    if ((temperatureChannel[channelID].currentTemperature > temperatureChannel[channelID].highLimit) | (temperatureChannel[channelID].currentTemperature < temperatureChannel[channelID].lowLimit))
        PlaySound(TEXT("C:\\Users\\Hassman\\Documents\\Visual Studio 2010\\Projects\\lab6\\lab6TemperatureControlTime\\lab3temperaturesensor\\untitled"),NULL,SND_FILENAME);
    sensorLog();
    if (_kbhit())
        key = _getch();         
    if ((key == 'P') | (key == 'p'))
    {
        silenceBeep();
    }
}
Était-ce utile?

La solution

It seems like you're forgetting to link your object file with the library that contains the implementation of that function while generating the executable output file.

According to The MSDN Library, using PlaySound requires linking with Winmm.lib.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top