Book a Demo

Author Topic: C++ and Addins...  (Read 3620 times)

paulourada

  • EA Novice
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
C++ and Addins...
« on: December 15, 2005, 07:26:54 am »
Ok, so this noob has done his homework and has seen that there is no support for writing C++ Addins.  :)

However, I don't really know C# nor VB nor Delphi, and neither do I particularly care to have to pick them up.  :P

So, at this point, the only impediment that I can find to writing pure C++ (not .Net) Addins is the lack of a header file that I can include to define an EA object, and thus create methods such as EA_Connect(EA.Repository Repository), etc.  Can anyone give me any ideas about how I should go about defining an EA object such that I can write a C++ Addin?

I'd be more than happy to post an example of how to write C++ Addins, if I could just get over this one small hurdle.  Or perhaps, therein lies the rub. :)

Much obliged,

Paul

EspressoE

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
  • A shot in the dark.
    • View Profile
Re: C++ and Addins...
« Reply #1 on: December 16, 2005, 02:50:50 pm »
A C++ add-in can be created.  Here's a quick-run-down of the steps:


  • Create an "ATL Project" in Visual Studio .NET (I will assume you used "MyAddIn" throughout the rest of this example).  Make sure that you include MFC support if you want to use AfxMessageBox which is nice for debugging.
  • In the Class View, right click your project name and choose "Add->Add Class"
  • Select "ATL Simple Object" and name your object (I will assume you used "TestClass" throughout the rest of this example).
  • Browse down to the interface for your class (ITestClass)
  • Right click and choose "Add->Add Method"  Fill in the parameters to create the following method.  Note that that last argument will be the retval.

    STDMETHODIMP CTestClass::EA_CONNECT(IDispatch* pRepository, BSTR* szReturn)
    {
       AFX_MANAGE_STATE(AfxGetStaticModuleState());

       CString szTemp(_T("a string"));

       AfxMessageBox(_T("EA_CONNECT called...."));

       *szReturn = szTemp.AllocSysString();

       return S_OK;
    }

  • Now repeat the last steps to make an add-in method as shown below.

    STDMETHODIMP CTestClass::HelloWorld(IDispatch* pRespository, VARIANT* vArgs, VARIANT* vReturn)
    {
       AFX_MANAGE_STATE(AfxGetStaticModuleState());
       CString szTemp;

       AfxMessageBox(_T("Hi from the method HelloWorld"));

       if ( vArgs->vt & VT_ARRAY )
       {
           if ( vArgs->vt & VT_BSTR )
           {   // it's an array of BSTR's
               // TODO:  parse everything here.
               // See http://www.codeproject.com/atl/safearray_macro.asp for guidance
           }

       }

       // Setup the return value
       vReturn->bstrVal = szTemp.AllocSysString();
       vReturn->vt = VT_BSTR;

       return S_OK;
    }

  • Compile the DLL and now add a registry key as follows:

    [HKEY_CURRENT_USER\Software\Sparx Systems\EAAddins\MyAddIn]
    @="MyAddIn.TestClass"

  • Now startup EA and add the following into one of your code templates (you can add as many parameters as you like, they will show up in the vArgs parameter).

    %EXEC_ADD_IN("MyAddIn","HelloWorld","Param1","Param2")%



There you go...  It's simple once you know how :)

-E
« Last Edit: December 16, 2005, 02:54:45 pm by EspressoE »

paulourada

  • EA Novice
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Re: C++ and Addins...
« Reply #2 on: December 16, 2005, 03:34:09 pm »
Thank you Eric, my colleague from three cubes over. :)  I am planning on putting together a zip of a VS project called Cpp_AddinFramework, which I will put on the EA Users Group website.

Paul