views:

201

answers:

2

I am not familiar with this, and can use a kick start.

I am using ATL (unmanaged C++) user control and would like to use the ShockWave ActiveX object. I need to know how to declare it so that I can set a property or call a method.

For instance, if I could assign a variable to it, then I would like to call 'variable->LoadMovie()'

I know this is super ridiculous... almost embarrassed to ask it here. ;) (almost)

A: 

I cut&paste the necessary code so many times I can't remember the exact syntax but you have to:

get a CComPtr<> of the correct interface, CreateInstance the object QueryInterface to get the interface you want (assuming you're not using the CComPtr)

then call methods on it.

Alternatively you can #import the dll, then the compiler will generate a c++ class with all the methods and properties for you.

gbjbaanb
oh no! a copy-paster!!!
xtofl
+1  A: 

If you #import the dll (which I recommend when working with COM because it makes your life SO much easier), you can use a smart pointer paired with the CLSID of the object. Remember that smart pointer classes have the post-fix 'Ptr' after the interface name.

For instance:

ISomeInterfacePtr pSomeInterface( CLSID_SomeComponent );
HRESULT hr = pSomeInterface->SomeMethod();

Hope that helps.

EDIT: If you want to check the HRESULT of the allocation, you can do the following:

ISomeInterfacePtr pSomeInterface = 0;
HRESULT hr = pSomeInterface.CreateInstance( CLSID_SomeComponent );
j0rd4n
Awesome, this was the key. Thank you.
Jason
No problem - happy coding...
j0rd4n