考虑以下程序:
#include <stdio.h>
#include <windows.h>
#include <mmdeviceapi.h>
#include <endpointvolume.h>
#include <math.h>
int main() {
IAudioEndpointVolume *wh;
IMMDevice *ya;
IMMDeviceEnumerator *xr;
CoInitialize(0);
CoCreateInstance(__uuidof(MMDeviceEnumerator), 0, CLSCTX_INPROC_SERVER,
__uuidof(IMMDeviceEnumerator), (void**)&xr);
xr->GetDefaultAudioEndpoint(eRender, eConsole, &ya);
ya->Activate(__uuidof(IAudioEndpointVolume), CLSCTX_ALL, 0, (void**)&wh);
float zu;
wh->GetMasterVolumeLevelScalar(&zu);
printf("%d\n", (int) round(100 * zu));
}
我可以毫无问题地将其编译为C ++:
x86_64-w64-mingw32-g++ vol.cpp -lole32
但是,如果我尝试将其编译为C:
x86_64-w64-mingw32-gcc vol.c -lole32
我收到如下错误:
error: ‘IAudioEndpointVolume’ has no member named ‘GetMasterVolumeLevelScalar’
该程序似乎并不是特别的“ C ++”,是什么原因导致了
问题?另外,我可以更改某些内容以使其编译为C吗?
最佳答案
这似乎做到了:
#include <stdio.h>
#include <initguid.h>
#include <mmdeviceapi.h>
#include <endpointvolume.h>
#include <math.h>
int main() {
IAudioEndpointVolume *wh;
IMMDevice *ya;
IMMDeviceEnumerator *xr;
CoInitialize(0);
CoCreateInstance(&CLSID_MMDeviceEnumerator, 0, CLSCTX_INPROC_SERVER,
&IID_IMMDeviceEnumerator, (void**)&xr);
xr->lpVtbl->GetDefaultAudioEndpoint(xr, eRender, eConsole, &ya);
ya->lpVtbl->Activate(ya, &IID_IAudioEndpointVolume, CLSCTX_ALL,
0, (void**)&wh);
float zu;
wh->lpVtbl->GetMasterVolumeLevelScalar(wh, &zu);
printf("%d\n", (int) round(100 * zu));
}
变化:
#include <initguid.h>
&CLSID_MMDeviceEnumerator
代替__uuidof(MMDeviceEnumerator)
lpVtbl->GetDefaultAudioEndpoint
代替GetDefaultAudioEndpoint
Source
关于c++ - IAudioEndpointVolume没有名为GetMasterVolumeLevelScalar的成员,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34561252/