Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I actually got this working myself using the Unified Event Model. Some notes from my experience in getting it working:</p> <ul> <li><p>You need to initialise ATL otherwise a null pointer error occurs when hooking up events. If you don't want to use ATL in your project (like I didn't - My project is plain C++), something like this in dllmain.cpp works fine (initialises ATL with a dummy module):</p> <pre><code>class CDummyModule : public CAtlDllModuleT&lt;CDummyModule&gt; {}; CDummyModule _Module; </code></pre></li> <li><p>You need to add "embedded_idl" to the end of the #import line.</p> <pre><code>#import "ComponentName.dll" embedded_idl </code></pre></li> <li><p>If the component has any structs embedded in it, you may get some MIDL2025 errors ("expecting a type specification near") due to a bug in Visual Studio (see <a href="https://connect.microsoft.com/VisualStudio/feedback/details/333473/midl2025-migrating-an-attributed-com-project-to-vs-2008-pro-with-exported-structures" rel="nofollow">https://connect.microsoft.com/VisualStudio/feedback/details/333473/midl2025-migrating-an-attributed-com-project-to-vs-2008-pro-with-exported-structures</a> and <a href="http://social.msdn.microsoft.com/forums/en-US/vcgeneral/thread/03b78133-5eac-4754-b9af-fc864a9389a3" rel="nofollow">http://social.msdn.microsoft.com/forums/en-US/vcgeneral/thread/03b78133-5eac-4754-b9af-fc864a9389a3</a>). Solution is to add:</p> <pre><code>[importidl("vsbugfix.idl")]; </code></pre></li> </ul> <p>And then add a</p> <pre><code>typedef struct StructName StructName; </code></pre> <p>For each struct that throws an error</p> <ul> <li><p>Once that's done, you should be able to initialise COM and create an instance of your object. Ugly example code:</p> <pre><code>IComponentName blah; HRESULT hr = CoInitialize(NULL); if (FAILED(hr)) { MessageBox(NULL, "Failed to initialize COM", "Hi!", 0); throw "Failed to initialize COM"; } try { hr = blah.CreateInstance("Something.Something"); if (FAILED(hr)) { CoUninitialize(); MessageBox(NULL, "Failed to initialize the COM library!!", "Hi!", 0); throw "Failed to initialize the COM library"; } } catch (...) { MessageBox(NULL, "Exception occured when initialising library!", "Error", 0); CoUninitialize(); throw "Exception occured when initialising library!"; } </code></pre></li> </ul> <p>Once you have your COM object, you can connect events as per the MSDN "Event Handling in COM" article:</p> <pre><code>__hook(&amp;IComponentNameEvents::OnWhatever, blah, &amp;EventHandlerClass::OnWhatever); </code></pre> <p>Be sure to unhook all events before calling CoUninitialize() otherwise you'll get errors.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload