AnsweredAssumed Answered

ICommandGroup::Activate crashes in C++ AddIn

Question asked by Mikhail Vashkevich on May 16, 2016
Latest reply on Nov 14, 2016 by Mikhail Vashkevich

Hi everybody!

Could anyone give me a hand in understanding what I'm doing wrong in the following part of code, written in C++?

The matter is that during the execution the line of code "pCommandGroup->Activate(&vbResult);" causes a crash.


extern "C" void __declspec (dllexport) Test_command()


extern "C" int __declspec (dllexport) OnUpdateTest()

     return 1;


HRESULT MyAddIn::ConnectToSW(LPDISPATCH ThisSW,long Cookie,VARIANT_BOOL *IsConnected)

      CComQIPtr <ISldWorks> pSldWorks=ThisSW;
      if (!pSldWorks)
          return S_FALSE;


      CComPtr <ICommandManager> pCommandManager;
      if (!pCommandManager)
          return S_FALSE;


      long lErrors=0;
      CComPtr <ICommandGroup> pCommandGroup;
      if (!pCommandGroup)
          return S_FALSE;


      long lCommandID1=0;


      VARIANT_BOOL vbResult=FALSE;
      pCommandGroup->Activate(&vbResult); // It crashes during the exacution


      return S_OK;


My assumption is that could be due to incorrect siganure for the callbacks in the method ICommandGroup::AddCommandItem2.  As a matter of fact, if I put there empty strings for the callbacks like this


the crash doesn't occur.

Unfortunately, all samples how to use this function are only available for C# and VB.

Thank you for any assistance!