我正在使用运行 visual studio 2010 的 Windows 7 并在 Cc 中编写。
这是我的代码片段。当满足条件(温度高于上限)时,我想从我的电脑播放一个 wav 文件。我在论坛上查了一下,我复制了与以前的海报相同的格式,但我仍然有同样的问题。我收到以下错误:
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
这是我的 CPP 中包含的头文件
#include "stdafx.h"
#include "lab4temperatureController.h"
#include <conio.h>
#include "console.h"
#include <iostream>
#include <Windows.h>
这是我调用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();
}
}
最佳答案
在生成可执行输出文件时,您似乎忘记了将目标文件与包含该函数实现的库链接起来。
根据 The MSDN Library ,使用 PlaySound
需要链接 Winmm.lib
。
关于c - 使用 PlaySound 播放 wav 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15624918/