title: How can I programmatically activate an OLE control via COM interfaces?
body: <p>I have an application which embeds a button control via ActiveX. The button was provided by a third party, and it implements a whole range of ActiveX interfaces (among which is <a href="http://msdn.microsoft.com/en-us/library/ms692646%28v=vs.85%29.aspx" rel="nofollow"><code>IOleInPlaceObject</code></a>). I do have an reference to the <a href="http://msdn.microsoft.com/en-us/library/ms680509%28v=VS.85%29.aspx" rel="nofollow"><code>IUnknown</code></a> implementation of the button.</p>
  
  <p>The problem I'm facing is that the <a href="http://msdn.microsoft.com/en-us/library/ms687282%28v=vs.85%29.aspx" rel="nofollow"><code>IOleWindow::GetWindow</code></a> function provided by the object always returns an error; the error code is 0x80004005 which is apparently a <a href="http://msdn.microsoft.com/en-us/library/aa378137%28v=vs.85%29.aspx" rel="nofollow">common HRESULT value</a> meaning <code>E_FAIL</code>. Not too descriptive.</p>
  
  <p>For what it's worth, the object also exposes a <code>hWnd</code> property via it's <a href="http://msdn.microsoft.com/en-us/library/ms221608.aspx" rel="nofollow"><code>IDispatch</code></a> implementation; querying it succeeds, but the value of the property is always zero.</p>
  
  <p>A bit of googling suggested that I may need to 'activate' the OLE object before the <code>hWnd</code> property yields a useful value. Does anybody know how to do this, is there a dedicated COM interface for activating OLE objects?</p>
  
  <p>Interestingly, the button <em>does</em> seem to have a window handle, as is visible in <a href="http://msdn.microsoft.com/en-us/library/aa264396%28v=vs.60%29.aspx" rel="nofollow">Spy++</a>.</p>
  
  <p><b>UPDATE:</b> I just found <a href="http://msdn.microsoft.com/en-us/library/ms690146%28v=vs.85%29.aspx" rel="nofollow"><code>IQuickActivate</code></a> which is implemented by the button control I'm dealing with, and which can be used to 'quickly' (ahem...) activate an item. However, filling the <a href="http://msdn.microsoft.com/en-us/library/ms688630%28v=vs.85%29.aspx" rel="nofollow"><code>QACONTAINER</code></a> structure seems to be quite a pain, so I'll rather not do that right now.</p>