3

I've been using this class for years and it's always "just there". I created a new project the other day and without explicitly doing anything, this class was available.

Now another new project complains it is not known. Both projects have the same #includes.

Neither project #includes comutil.h. Neither project uses the commsuppw.lib library (https://msdn.microsoft.com/en-us/library/zthfhkd6(v=vs.110).aspx). The only possibly related header included is objbase.h, which both projects include.

So why does one project build happily and the other doesn't? How is the one that works able to link without the needed library?

I think this is one of those "I've been coding all day and my brain has stopped working issues" but still... what?

Mr. Boy
  • 60,845
  • 93
  • 320
  • 589
  • Heck, I tried using `_bstr_t` in another project I created at the same time and it works just fine. Both were created as standard Windows console applications and I didn't add additional libs... why is one magically working and the other not? – Mr. Boy Oct 22 '15 at 17:57
  • The #import directive will generate a .tlh file that automatically #includes it. Not much magic there, just not very visible. – Hans Passant Oct 22 '15 at 18:20
  • I _think_ this might be it, that one project was explicitly importing a tlh and the other wasn't. However not all my projects do this... some where some header was including a header that included comdef.h I suppose. I'm really not a fan of #import! – Mr. Boy Oct 23 '15 at 09:48
  • Hans, thank you! I was searching for comdef.h for 30 minutes never thinking of the tlh files. – Dietrich Baumgarten Feb 28 '20 at 11:22

1 Answers1

8

I needed to #include <comdef.h>

Apparently this automagically imports the required libs.

Mr. Boy
  • 60,845
  • 93
  • 320
  • 589