c - 使用 PlaySound 播放 wav 文件

标签 c linker playsound

我正在使用运行 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/

相关文章:

作为 cron 运行的 C 脚本给予权限被拒绝错误

c++ - 导入库如何工作以及为什么 MinGW 不需要它们?

c++ - 子弹物理,Visual Studio 中的链接错误

c++ - Makefile 更新库依赖

C++ PlaySound() 错误

c++ - 停止后制作音频 'resume'?

c - 在头文件中使用 typedef 结构体向前声明函数

c++ - 如何在 C 中限制套接字连接的带宽?

c - 将变量传递给函数并更改其全局值

delphi - sndPlaySound 或 PlaySound on KeyPress - 播放键盘声音