IAudioEndpointVolume没有名为GetMasterVolumeLevelScalar的成员

IAudioEndpointVolume has no member named GetMasterVolumeLevelScalar

本文关键字:GetMasterVolumeLevelScalar 成员 IAudioEndpointVolume      更新时间:2023-10-16

考虑这个程序:

#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("%dn", (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("%dn", (int) round(100 * zu));
}

更改:

  1. #include <initguid.h>
  2. &CLSID_MMDeviceEnumerator而不是__uuidof(MMDeviceEnumerator)
  3. lpVtbl->GetDefaultAudioEndpoint而不是GetDefaultAudioEndpoint

相关文章:
  • 没有找到相关文章