'How to obtain the permission status of application microphone through C++ on Windows system?
I have used the following two methods:
1、
winrt::param::hstring capabilityName(L"Microphone");
auto m_appCapability = winrt::Windows::Security::Authorization::AppCapabilityAccess::AppCapability::Create(capabilityName);
winrt::Windows::Security::Authorization::AppCapabilityAccess::AppCapabilityAccessStatus status = m_appCapability.CheckAccess();
2、
Windows::Media::Capture::MediaCapture *_mediaCapture = ::new Windows::Media::Capture::MediaCapture();
Windows::Media::Capture::MediaCaptureInitializationSettings _mediaSettings;
_mediaSettings.StreamingCaptureMode(Windows::Media::Capture::StreamingCaptureMode::AudioAndVideo);
hresult h = 0;
try
{
auto a = _mediaCapture->InitializeAsync(_mediaSettings);
a.get();
}
catch (winrt::hresult_error const& ex)
{
std::cout << ex.code() << std::endl;
}
These two methods can effectively and accurately obtain the permission status of the application microphone. However, they also have a problem: only win10 can be compatible and cannot run on win7 system (lack of many DLL files and other unknown compatibility errors), and the compilation requires C + + 17 (some programming syntax features of winrt)
So I'm looking for a way to get the permission status of application microphone through C + + programming on Windows system without version compatibility problem. Can someone provide some better ways?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|