Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use WASAPI in C code on MinGW64? If so, how?

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++?

like image 658
Manatee Pink Avatar asked Dec 01 '25 18:12

Manatee Pink


1 Answers

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.

like image 161
einpoklum Avatar answered Dec 04 '25 09:12

einpoklum



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!