[英]QT Include Windows SDK Library
I am new to Qt and I want to use the AudioSessionManager2
from the Windows SDK.我是 Qt 的AudioSessionManager2
,我想使用 Windows SDK 中的AudioSessionManager2
。 In Qt Creator using this example I've written appended code below.在使用此示例的Qt Creator 中,我在下面编写了附加代码。
When compiling I get the messages编译时我收到消息
undefined reference to `__imp_CoCreateInstance'对 `__imp_CoCreateInstance' 的未定义引用
undefined reference to `IID_IAudioSessionManager2'对“IID_IAudioSessionManager2”的未定义引用
In the documentation for the core audio APIs , Microsoft states the APIs are implemented in Mmdevapi.dll and Audioses.dll.在核心音频 API的文档中,Microsoft 声明 API 是在 Mmdevapi.dll 和 Audioses.dll 中实现的。 While I hoped to find two matching .lib files the SDK I downloaded with Visual Studio, I only found mmdevapi.lib.虽然我希望在我使用 Visual Studio 下载的 SDK 中找到两个匹配的 .lib 文件,但我只找到了 mmdevapi.lib。 After copying it to my project and adding it to the qt project file like below I still had no success with the same error message.将它复制到我的项目并将其添加到 qt 项目文件中后,如下所示,我仍然没有成功并出现相同的错误消息。
How am I supposed to know which lib files to import for which functions?我应该如何知道要为哪些函数导入哪些 lib 文件?
How do I get these lib files?我如何获得这些lib文件?
Did I import the lib file correctly?我是否正确导入了 lib 文件?
audiomanager.h:音频管理器.h:
#ifndef AUDIOMANAGER_H
#define AUDIOMANAGER_H
#include <mmdeviceapi.h>
#include <audiopolicy.h>
#include "utils/SafeRelease.h"
class AudioManager {
public:
AudioManager();
~AudioManager();
private:
IAudioSessionManager2 *pSessionManager = nullptr;
HRESULT init();
};
#endif // AUDIOMANAGER_H
audiomanager.cpp音频管理器.cpp
#include "audiomanager.h"
AudioManager::AudioManager () {
this->init();
}
AudioManager::~AudioManager () {
SafeRelease(&pSessionManager);
}
HRESULT AudioManager::init () {
HRESULT hr = S_OK;
// initialize needed vars
IMMDeviceEnumerator *pDeviceEnumerator = nullptr;
IMMDevice *pDevice = nullptr;
// get device enumerator
hr = CoCreateInstance(
__uuidof(MMDeviceEnumerator),
nullptr,
CLSCTX_ALL,
IID_PPV_ARGS(&pDeviceEnumerator)
);
if (FAILED(hr))
goto done;
// get the default audio output (for consoles)
// !!! only for consoles? (games, system, etc.), no music, video
pDeviceEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &pDevice);
if (FAILED(hr))
goto done;
// get the session manager
hr = pDevice->Activate(
IID_IAudioSessionManager2,
CLSCTX_ALL,
nullptr,
reinterpret_cast<void**>(&pSessionManager)
);
done:
SafeRelease(&pDeviceEnumerator);
SafeRelease(&pDevice);
return hr;
}
Line from Qt Project file Qt 项目文件中的行
LIBS += "$$PWD\..\libs\mmdevapi.lib"
After hours of trying I figured out it would work with经过数小时的尝试,我发现它可以与
// get the session manager
hr = pDevice->Activate(
__uuidof(IAudioSessionManager2),
CLSCTX_ALL,
nullptr,
reinterpret_cast<void**>(&pSessionManager)
);
instead of代替
// get the session manager
hr = pDevice->Activate(
IID_IAudioSessionManager2,
CLSCTX_ALL,
nullptr,
reinterpret_cast<void**>(&pSessionManager)
);
I don't know, why I cannot find proper libraries for the IID_IAudioSessionManager
, nor why the Microsoft source code example lists this, but the other provided option seems to work.我不知道,为什么我找不到合适的IID_IAudioSessionManager
库,也不知道为什么 Microsoft 源代码示例列出了这个,但另一个提供的选项似乎有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.