Question

What is the C++ equivalent to GetObject in JavaScript and VBScript?

The closest match I found to my question is:

http://codewiz51.blogspot.com/2008/06/vb-script-getobject-c-api-cogetobject.html

However the sample use an unexisting interface and asking for the IUnknown returns null. Did someone have an example that works?

Was it helpful?

Solution

I figured out the issue. The object I wanted to access was

winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv

I mistakenly took \\ for an escapement. In C++ the correct query is :

::CoGetObject(L"winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\default:StdRegProv", NULL, IID_IUnknown, (void**)&pUnk);

Thank you :)

OTHER TIPS

The article you linked to is correct. You may be providing the wrong interface ID, or the display name could be wrong. You should check the return value from the CoGetObject call.

If asking for IUnknown returns NULL, there is no object by that name. Each COM object implements IUnknown.

Have you initialized COM before making any COM calls?

Look up CoInitializeEx.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top