Undefined reference to CLSID_MMDeviceEnumerator and IID_IMMDeviceEnumerator

做~自己de王妃 提交于 2019-12-05 22:38:32

The solution, when using MinGW-w64, is to include the header #include <initguid.h>, before including headers that contain COM identifiers such as mmdeviceapi.h, endpointvolue.h.

Then no extra declarations are needed and identifiers can be used directly.

Solution:

#include <windows.h>
#include <initguid.h>
#include <mmdeviceapi.h>
#include <endpointvolume.h>

#include <stdlib.h>
#include <stdio.h>

int main( void )
{
    CoInitialize( NULL );

    LPVOID device = NULL;
    const HRESULT ok = CoCreateInstance(    &CLSID_MMDeviceEnumerator, NULL, 
                                            CLSCTX_INPROC_SERVER, &IID_IMMDeviceEnumerator, 
                                            &device );  
    CoUninitialize();

return EXIT_SUCCESS;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!