c++ - IAudioClient::Initialize 方法的未解析外部符号。应用程序接口(interface)

标签 c++ audio com wasapi

我正在尝试通过 WASAPI 工具启动并运行输入音频流录制样本。 这是我的意思的链接:http://msdn.microsoft.com/en-us/library/windows/desktop/dd370800(v=vs.85).aspx

相关代码如下:

#include "InputTest.h"
#include "Audioclient.h"
#include "Mmdeviceapi.h"

void InputTest::TakeInput()
{
HRESULT hr;

//Parameter variables for stream initialization
AUDCLNT_SHAREMODE ShareMode = AUDCLNT_SHAREMODE_SHARED;
DWORD da = 0;
REFERENCE_TIME bufferDuration = 10;
REFERENCE_TIME periodicity = 5;
WAVEFORMATEX pFormat;
LPCGUID AudioSessionGuid = NULL;
GUID guid2 = *AudioSessionGuid;
HRESULT guidError = UuidCreate(&guid2);  //could do some error checking here.    //project ->       properties -> Linker -> Command Line -> Rpctr4.lib

//guid2 now has a generated value
//give ASG the address of the newly generated guid2
AudioSessionGuid = &guid2;


//Instantiate WaveFormat
pFormat.wFormatTag = WAVE_FORMAT_PCM;
pFormat.cbSize = 10;  //extra information sent over stream. Usually ignored in PCM format.

//If wFormatTag is WAVE_FORMAT_PCM, nAvgBytesPerSec must equal nSamplesPerSec × nBlockAlign
pFormat.nAvgBytesPerSec = 0;
pFormat.nSamplesPerSec = 0;
pFormat.nBlockAlign = 0;

pFormat.nChannels = 2;
pFormat.wBitsPerSample = 16; //PCM standard

//Pointer for stored audio stream
IAudioClient *iac = NULL;

//Endpoint device selection
IMMDeviceEnumerator *pEnumerator = NULL;
IMMDevice *pDevice = NULL;

HRESULT de;
de = pEnumerator -> GetDefaultAudioEndpoint(eRender, eConsole, &pDevice);

hr = iac -> IAudioClient::Initialize(ShareMode, da, bufferDuration, periodicity, &pFormat, AudioSessionGuid);
}`

完整错误信息:

error LNK2019: unresolved external symbol "public: virtual long __stdcall
IAudioClient::Initialize(enum _AUDCLNT_SHAREMODE,unsigned long,__int64,__int64,struct 
tWAVEFORMATEX const *,struct _GUID const *)" (?
Initialize@IAudioClient@@UAGJW4_AUDCLNT_SHAREMODE@@K_J1PBUtWAVEFORMATEX@@PBU_GUID@@@Z) 
referenced in function "public: void __thiscall InputTest::TakeInput(void)" (?
TakeInput@InputTest@@QAEXXZ)

非常感谢任何建议,因为我现在正在阅读一本很好的 C++ 实践书籍。这个错误是怎么回事?

最佳答案

不正确:

hr = iac -> IAudioClient::Initialize(...

正确:

hr = iac->Initialize(...

你应该在这里调用 COM 接口(interface)指针的虚方法,而不是绕过 vtable 的特定函数(相关讨论参见 this question)。

关于c++ - IAudioClient::Initialize 方法的未解析外部符号。应用程序接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25831936/

相关文章:

java - 通过AudioSystem.getAudioInputStream(file)读取MP3文件出现异常

actionscript-3 - Flash AS3 结束时如何循环播放声音?

javascript - 使用可选输入设置 ActiveX 属性

c++ - 在 C++ 中加载 CLR,Start() 问题

c++ - Zenlib 错误 : undefined reference to Open function call which uses typedef

java - 使用 CREATE_NEW_PROCESS_GROUP 创建主机时,将 Ctrl+C 发送到子进程

c++ - 编译 C++ 代码时出现编译错误

c++ - 复制构造函数在调用时抛出 std::bad_alloc

javascript - HTML 中的多个音频文件,如果单击两个,较旧的文件应停止播放

delphi - 如何在Delphi 7中获取GIT?