Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to add new functions to a COM .dll created by a Visual Studio C++ ATL Project
    text
    copied!<p>I'm trying to create a very basic COM dll for inclusion in a C# project, to then use to wrap up some C++ functionality into a COM module for inclusion in a C# project (the language used by the rest of the code base).</p> <p>I included the COM dll, added a class to the COM dll and instantiated it in the C# code, but so far I haven't been able to add new functionality to the new class.</p> <p>Here's what I did: </p> <ol> <li>New Visual C# Windows Forms Application </li> <li>Right click solution->Add->New Project... </li> <li>Add New Visual C++ ATL Project (called MyCOMDLL) </li> <li>Default options chosen in ATL Project Wizard (I've also tried ticking 'Support COM+ 1.0')</li> <li>Right click MyCOMDLL project->Add->Class </li> <li>Add New Visual C++ ATL COM+ 1.0 Component </li> <li>Typed 'MyCOMObject' into Short name, which automatically populated the other fields in the 'Names' tab </li> <li>Left the other settings as default </li> <li>Built the MyCOMDLL project</li> <li>Add a reference to the new MyCOMDLL.dll to the C# Windows Forms Application <li>Right Click C# Windows Forms Application Project->Properties <li>On the Build tab set Platform target to x86 <li>Add "using MyCOMDLLLib;" to Form1.cs file <li>Add a button to the Form and in the button click function add</li> </ol> <p><pre><code>MyCOMDLLLib.MyCOMObjectClass myVariable = new MyCOMObjectClass();</pre></code></p> <p>I've tried various things so won't list any except the most obvious here - I tried adding a class method to MyCOMObject.h:</p> <p><pre><code>// CMyCOMObject class ATL_NO_VTABLE CMyCOMObject : public CComObjectRootEx, public CComCoClass, public IDispatchImpl { public: CMyCOMObject() { }</p> <pre><code>DECLARE_PROTECT_FINAL_CONSTRUCT() HRESULT FinalConstruct() { return S_OK; } void FinalRelease() { } </code></pre> <p>DECLARE_REGISTRY_RESOURCEID(IDR_MYCOMOBJECT)</p> <p>DECLARE_NOT_AGGREGATABLE(CMyCOMObject)</p> <p>BEGIN_COM_MAP(CMyCOMObject) COM_INTERFACE_ENTRY(IMyCOMObject) COM_INTERFACE_ENTRY(IDispatch) END_COM_MAP()</p> <p>// IMyCOMObject public: // SB: My attempt at adding a new method int ReturnTwo() { return 2; } };</pre></code></p> <p>The ReturnTwo method was visible in the class view of CMyCOMObject, but not visible in the class view of MyCOMObjectClass in the C# Windows Forms Application project. </p> <p>Any help much appreciated.</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