【问题标题】:Using PlaySound to play a wav file使用 PlaySound 播放 wav 文件
【发布时间】:2013-03-25 21:16:01
【问题描述】:

我正在使用运行 Visual Studio 2010 的 Windows 7 并在抄送中写作。

这是我的代码的 sn-p。当满足条件(温度高于上限)时,我想从我的电脑播放一个 wav 文件。我检查了论坛,我复制了与以前的海报相同的格式,如果我仍然有同样的问题。我收到以下错误:

1>lab4TemperatureController.obj:错误 LNK2019:无法解析的外部符号 _imp_PlaySoundA@12 在函数“void __cdecl activateAlarm(int,int)”(?activateAlarm@@YAXHH@Z) 中引用/p>

1>C:\Users\Hassman\Documents\Visual Studio 2010\Projects\lab6\lab6TemperatureControlTime\Debug\lab3temperaturesensor.exe : 致命错误 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();
    }
}

【问题讨论】:

    标签: c linker playsound


    【解决方案1】:

    在生成可执行输出文件时,您似乎忘记将目标文件与包含该函数实现的库链接。

    根据The MSDN Library,使用PlaySound需要与Winmm.lib链接。

    【讨论】:

      猜你喜欢
      • 2012-10-10
      • 2012-12-09
      • 1970-01-01
      • 2012-08-03
      • 2012-04-16
      • 1970-01-01
      • 1970-01-01
      • 2011-01-25
      • 2015-05-28
      相关资源
      最近更新 更多