Can't find include file <mmdeviceapi.h>.

Started by neo313, July 28, 2015, 04:58:45 AM

Previous topic - Next topic

neo313

main.c(4): fatal error #1035: Can't find include file <mmdeviceapi.h>.

How can I use the MMDevice API?

This is usually done in C++:

  const CLSID CLSID_MMDeviceEnumerator = __uuidof(MMDeviceEnumerator);
  const IID IID_IMMDeviceEnumerator = __uuidof(IMMDeviceEnumerator);
  hr = CoCreateInstance(
         CLSID_MMDeviceEnumerator, NULL,
         CLSCTX_ALL, IID_IMMDeviceEnumerator,
         (void**)&pEnumerator);

including Mmdeviceapi.h and ole32 library.

How can I use this api in C with Pelles?

Bitbeisser

With a quick search, all I found about that API is that it is C# (not C++) and thus very likely not going to work with Pelle's C, unless someone has a wrapper for that...

Ralf

neo313

#2
Quote from: Bitbeisser on July 28, 2015, 05:49:51 AM
With a quick search, all I found about that API is that it is C# (not C++) and thus very likely not going to work with Pelle's C, unless someone has a wrapper for that...

Ralf

No. The API is C/C++. It is a part of [Core Audio Interfaces](https://msdn.microsoft.com/en-us/library/windows/desktop/dd370805%28v=vs.85%29.aspx). For example, it plays a part in controlling user sound volume in Windows.

TimoVJL

Basic idea for that
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <ole2.h>
//#include <mmdeviceapi.h>
//#include <endpointvolume.h>

#pragma comment(lib, "ole32.lib")

//extern
const CLSID CLSID_MMDeviceEnumerator  = {0xBCDE0395,0xE52F,0x467C,0x8E,0x3D,0xC4,0x57,0x92,0x91,0x69,0x2E}; // BCDE0395-E52F-467C-8E3D-C4579291692E
//extern
const IID IID_IMMDeviceEnumerator = {0xA95664D2,0x9614,0x4F35,0xA7,0x46,0xDE,0x8D,0xB6,0x36,0x17,0xE6}; // A95664D2-9614-4F35-A746-DE8DB63617E6

int main(void)
{
CoInitialize(NULL);

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

return EXIT_SUCCESS;
}
May the source be with you

neo313

#4
Quote from: TimoVJL on July 28, 2015, 06:16:34 AM
Basic idea for that

Interesting. I see you have plucked out the values of CLSID_MMDeviceEnumerator and IID_IMMDeviceEnumerator out of mmdeviceapi.h.

Including mmdeviceapi.h is necessary to get proper function and struct definitions. Unfortunately trying to compile with that header fails.

TimoVJL

#5
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <ole2.h>

#define __RPC__deref_out
#define __in
#define __out
#define __in_opt
#define __deref_out
#include <mmdeviceapi.h>
//#include <endpointvolume.h>

#pragma comment(lib, "ole32.lib")

//extern
const CLSID CLSID_MMDeviceEnumerator  = {0xBCDE0395,0xE52F,0x467C,0x8E,0x3D,0xC4,0x57,0x92,0x91,0x69,0x2E}; // BCDE0395-E52F-467C-8E3D-C4579291692E
//extern
const IID IID_IMMDeviceEnumerator = {0xA95664D2,0x9614,0x4F35,0xA7,0x46,0xDE,0x8D,0xB6,0x36,0x17,0xE6}; // A95664D2-9614-4F35-A746-DE8DB63617E6

int main(void)
{
CoInitialize(NULL);

IMMDeviceEnumerator *pEnumerator = NULL;
HRESULT ok = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL,
CLSCTX_INPROC_SERVER, &IID_IMMDeviceEnumerator,
(void**)&pEnumerator);
if (!ok) {
ok = pEnumerator->lpVtbl->Release(pEnumerator);
}
CoUninitialize();

return EXIT_SUCCESS;
}
May the source be with you

neo313

Awesome.

Can you also make endpointvolume.h work? I tried and I don't think it is possible since there is a mess with some missing defines or something like that.

frankie

Get the PellesC extension here, I've added "mmdeviceapi.h" & "winapifamily.h".
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

TimoVJL

May the source be with you