Log in

No account? Create an account
06 January 2006 @ 08:02 am
I hate WMI. I hate Microsoft. I hate stupid underdocumented APIs and code examples which conflict with each other.

My boss has decided that i should implement a WMI ("Windows Management Instrumentation") provider for our product. He spent about a day working on it himself before deciding it would take forever and handing it off to me, which was probably a bad sign. I don't mind working on a long term project (though the last one didn't turn out so well) but i can't even get the damn thing _started_ in a working manner.

My boss gave me a book called "Developing WMI Solutions" and said i should look at MSDN as well. Unfortunatly the examples given in the book and MSDN are very different. Furthermore my boss specified that it should be a "decoupled provider," and while MSDN gives examples of both coupled and decoupled providers the book doesn't even mention the difference. MSDn gives sample code on how to hook a decoupled provider into an application but as far as i can tell doesn't say what if any changes should be made to the provider itself. And their example code doesn't work. Particularly the bit:

"// CMyProv is the class added for WMI instance / event provider
HRESULT hr = CMyProv::CreateInstance(NULL,&pIUnknown);"

I don't know what "CMyProv" is supposed to be exactly. I tried hooking it up to the simple provider i had going and got the error:

"error C2664: 'HRESULT _com_ptr_t<_iiid>::CreateInstance(const CLSID &,IUnknown *,DWORD) throw()' : cannot convert parameter 2 from 'IUnknown **__w64 ' to 'const CLSID &'"

Which seems to mean, "we failed to convert the second parameter into the type of the first parameter," which is certainly one of the more nonsensical errors i've ever heard.

And if i manage to get the decoupled/coupled issues worked out my boss also wants me to right it as a dll rather than an exe, which MSDN mentions several times is one of the possible ways to write a provider but doesn't go into detail as to what particular pitfalls that method may entail.

And just as a little icing on the cake, while googling about to try and find some help i found a MSDN blog complaining that they couldn't get WMI working until they went and talked to some people from the WMI team, which is also a bad sign =P
Current Mood: frustratedfrustrated
Dalton Graham: stacksdaltong on January 6th, 2006 05:09 pm (UTC)
I know nothing about any of this, but it looks like you're calling CreateInstance with 3 parameters instead of 2?
DonAithnendonaithnen on January 6th, 2006 05:29 pm (UTC)
Well the instance that it looks like it's _trying_ to call is

HRESULT CreateInstance(const CLSID& rclsid, IUnknown* pOuter = NULL, DWORD dwClsContext = CLSCTX_ALL) throw()

So it shouldn't need the third parameter or even the third. I did try forcing the third parameter but that didn't make any difference, it still got hung up on the same error.
Kirinkirinn on January 7th, 2006 02:10 am (UTC)
In case it makes you feel any better, I don't get it either. ^_^;

I can't see how the compiler error makes sense, and MS APIs in general make my head want to explode. I'm so glad we're using wxWidgets instead of MFC or whatever else directly. (wxW is a cross-platform GUI/utils library that abstracts the underlying platform stuff into a *sensible* API. Our app isn't even cross-platform, but it's worth it anyway for the sanity.)