Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The instructions you've followed are for calling functions in an ordinary DLL, not a COM DLL. To access a COM DLL you need to go through COM.</p> <p>You don't link to the DLL's lib file or include any headers, and you don't need to move the DLL.</p> <p>First, make sure the DLL is registered by running regsvr32 on it.</p> <pre><code>regsvr32 "c:\..\..\xyz.dll" ; insert the correct path </code></pre> <p>Then add an #import directive to your project's stdafx.h, containing the path to the DLL.</p> <pre><code>#import "c:\..\..\xyz.dll" // insert the correct path </code></pre> <p>Right click stdafx.cpp in the file view and choose <strong>compile</strong>. This will generate the wrapper "smart pointer" classes you need to access your DLL. The smart pointer classes have the same names as the interfaces in your DLL, but with "Ptr" on the end.</p> <p>Look at the file with a .tlh extension and the same name as your DLL in your Debug directory. It begins with a C++ namespace declaration. This is the namespace in which the objects you are going to create from the DLL reside.</p> <p>Say the namespace is <em>XYZ</em> and you want to instantiate a <em>Cx</em> object, which exposes the <em>Ix</em> interface. You would do:</p> <pre><code>try { XYZ::IxPtr obj; obj.CreateInstance(__uuidof(XYZ::Cx)); obj-&gt;func(); } catch (_com_error e) { printf("Error: %S\n", e.Description()); printf("Error: %S\n", e.ErrorMessage()); } </code></pre> <p>You can then continue to use it just like an ordinary pointer. You don't delete it when you have finished with it though, it will be destroyed automatically when it goes out of scope.</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