AudioDeviceManager initialise() assertion


#1

Hi everybody,

I'm a newbie into the JUCE world, and I have a simple question :

I want to use JUCE without all the Juce application stuff (because at the end I want to embbed it in an existing engine), but it seems like it does not like this...

When I try to initialise an AudioDeviceManager() in a simple main() function, I got an assertion in  CoCreateInstance() :

jassert (hr != CO_E_NOTINITIALIZED); // You haven't called CoInitialize for the current thread!

The call stack :

>    MidiTest.exe!juce::ComSmartPtr<juce::IMMDeviceEnumerator>::CoCreateInstance(const _GUID & classUUID, unsigned long dwClsContext)  Ligne 92 + 0x21 octets    C++
     MidiTest.exe!juce::WasapiClasses::WASAPIAudioIODeviceType::scan(juce::StringArray & outputDeviceNames, juce::StringArray & inputDeviceNames, juce::StringArray & outputDeviceIds, juce::StringArray & inputDeviceIds)  Ligne 1355 + 0x12 octets    C++
     MidiTest.exe!juce::WasapiClasses::WASAPIAudioIODeviceType::scanForDevices()  Ligne 1241    C++
     MidiTest.exe!juce::AudioDeviceManager::scanDevicesIfNeeded()  Ligne 323 + 0x1e octets    C++
     MidiTest.exe!juce::AudioDeviceManager::initialise(const int numInputChannelsNeeded, const int numOutputChannelsNeeded, const juce::XmlElement * const e, const bool selectDefaultDeviceOnFailure, const juce::String & preferredDefaultDeviceName, const juce::AudioDeviceManager::AudioDeviceSetup * preferredSetupOptions)  Ligne 191    C++

The two first lines of my main throwing this assertion :

  AudioDeviceManager audioManager;
  audioManager.initialise(1, 1, nullptr, true);

Thanks in advance for your help !

 


#2

The assertion, which you've helpfully copied into your post, already explains exactly what you've done wrong.


#3

Okay, I feel like an idiot ! I thought that CoInitialize was a Juce method. As I was in the main function, I did not understand how to "CoInitialize" a thread that I did not create...

I have a lot to learn about the windows SDK...


#4

The program has to follow WMI (Windows Management Instrumentation); so in order for your program to run, your thread has to be CoInitialized.

drop:

    HRESULT hr;
    hr = CoInitializeEx(0, COINIT_MULTITHREADED);

in your main and you should be fine. Use CoInitializeEx() instead of CoInitialize()