Conflict between GetDC and CoCreateInstance

I did some experimenting and tried to implement sound with WASAPI instead of DirectSound. For some reason, calling to CoCreateInstance to get an IMMDeviceEnumerator makes my compile take around 20 seconds instead of being instant. Anybody have any ideas why? I'd imagine it's something obvious that I'm not knowledgeable enough to see.

EDIT: Changed the thread subject for clarity.

Edited by Aaron on
You can try compare your implementation with my WASAPI code to find differences: https://forums.handmadehero.org/i...hp/forum?view=topic&catid=4&id=87
For me CoCreateInstance is instantaneous. Have you called CoInitializeEx?

Edited by Mārtiņš Možeiko on
Yeah, I have.

Only difference I see between our implementations is that you only pass CoCreateInstance 4 parameters. The documentation mentions 5:

1
2
3
4
5
6
7
HRESULT CoCreateInstance(
  _In_   REFCLSID rclsid,
  _In_   LPUNKNOWN pUnkOuter,
  _In_   DWORD dwClsContext,
  _In_   REFIID riid,
  _Out_  LPVOID *ppv
);



Also, it runs fine in the debugger with no noticeable hangups. It's just compiling that takes forever, if that was unclear.
IID_PPV_ARGS macro expands to two arguments:
1
#define IID_PPV_ARGS(ppType) __uuidof(**(ppType)), IID_PPV_ARGS_Helper(ppType)


Oh, compile takes long. I though running CoCreateInstance takes long. I missed that part. Are you sure it is CoCreateInstance that gives you problem? If you comment it out, everything compiles fast? Maybe anti-virus is a problem?

Edited by Mārtiņš Možeiko on
Oh, right, the macro. Brain appears to be running out of energy.

Yeah, I just reconfirmed that commenting out the CoCreateInstance call makes it compile instantly. Earlier I was running into messages about the incremental linker, having to do a full link etc. though I'm not getting those messages right now. Compiler output is normal, just takes longer.

EDIT: Playing around a bit more (just with commenting/uncommenting the CoCreateInstance call) and now even with it commented out I had a long compile. But it seems like if I comment it out, have one long compile, then compile again with the same exact code, it compiles normally.

Edited by Aaron on
I've yet to look into why this fixed it, but it did. The problem arises when I use GetDC before using CoCreateInstance. For example, if I call GetDC the line before - compile takes 20 seconds and the program doesn't run right. If I call GetDC the line after - everything is fine. Pretty baffling, I have no idea why those two would cause some sort of conflict - in compilation, no less.