最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

compiler errors - Can I use WASAPI in C code on MinGW64? If so, how? - Stack Overflow

programmeradmin3浏览0评论

I am using MinGW64 which has the necessary headers to use WASAPI. However, following the WASAPI programming guide I added following code:

const CLSID CLSID_MMDeviceEnumerator = __uuidof(MMDeviceEnumerator);
const IID IID_IMMDeviceEnumerator = __uuidof(IMMDeviceEnumerator);
const IID IID_IAudioClient = __uuidof(IAudioClient);
const IID IID_IAudioRenderClient = __uuidof(IAudioRenderClient);

however, when I compile the code I get following error

error: implicit declaration of function '__uuidof' [-Wimplicit-function-declaration]

I checked, I am linking against Ole32.lib, so I thought that should be all, but apparently not so.

So my suspicion is that it has something to do with the C/C++ mismatch. But is that true? Can WASAPI only be used with C++?

I am using MinGW64 which has the necessary headers to use WASAPI. However, following the WASAPI programming guide I added following code:

const CLSID CLSID_MMDeviceEnumerator = __uuidof(MMDeviceEnumerator);
const IID IID_IMMDeviceEnumerator = __uuidof(IMMDeviceEnumerator);
const IID IID_IAudioClient = __uuidof(IAudioClient);
const IID IID_IAudioRenderClient = __uuidof(IAudioRenderClient);

however, when I compile the code I get following error

error: implicit declaration of function '__uuidof' [-Wimplicit-function-declaration]

I checked, I am linking against Ole32.lib, so I thought that should be all, but apparently not so.

So my suspicion is that it has something to do with the C/C++ mismatch. But is that true? Can WASAPI only be used with C++?

Share Improve this question edited Feb 15 at 21:21 einpoklum 132k76 gold badges413 silver badges849 bronze badges asked Feb 15 at 20:21 Manatee PinkManatee Pink 2831 silver badge7 bronze badges 3
  • have you seen this stackoverflow/a/8868812/22147 ? – Gordon Childs Commented Feb 15 at 20:35
  • duplicate stackoverflow/questions/18606546/how-to-use-uuidof-in-mingw – n. m. could be an AI Commented Feb 16 at 7:56
  • @GordonChilds I have not. However, that thread doesn't seem to help since prepending IID to MMDeviceEnumerator results in the error "'IID_MMDeviceEnumerator' undeclared here" – Manatee Pink Commented Feb 17 at 12:03
Add a comment  | 

1 Answer 1

Reset to default 3

The definitions you mentioned use __uuid(). This is an MSVC builtin, and is not defined by the C++ language standard, including in particular not being defined by the standard C++ library.

That means you can only use code or headers, which rely on __uuid(), if you compile them using MSVC; while you are using MinGW, i.e. a GNU toolchain, including the GCC compiler.

I am not familiar with WASAPI; it is theoretically possible that it can be adapted/ported to a non-MSVC compiler. In this answer, it is suggested that there may be an alternative to uuidof, using macros with a UUID defined per interface.

But as thigs stand, the answer is: No, you can't use WASAPI with C on MinGW64.

发布评论

评论列表(0)

  1. 暂无评论