WASAPI - trouble with CoCreateInstance method

3

I am trying to capture audio from the mic using the windows core audio APIs

The relevant lines of code are

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

hr returns the following value-

0x800401f0 : CoInitialize has not been called.

I have adapted the sample program from the msdn page - Capturing an audio stream

What could be wrong? Also I don't understand what the error means - from the descriptions I got from Google search and all.

I am using Visual studio 2012 express on Win7 Home Pro x64.

audio
wasapi
asked on Stack Overflow Oct 22, 2012 by Srinath Ravichandran • edited Jun 27, 2016 by mpromonet

1 Answer

3

Isn't the error message clear enough? You need to call CoInitialize before calling CoCreateInstance (or using COM in any other way).

answered on Stack Overflow Oct 22, 2012 by user1610015

User contributions licensed under CC BY-SA 3.0