0 Replies Latest reply on May 17, 2016 4:42 PM by Nhan Vu

    Hi all,

    Nhan Vu

      I have this issue about Solidworks Add-ins:

      I'm using C++ and my Solidworks version is 2014.

      First, I launch the Solidworks and load Add-in programmatically:


      CComPtr<ISldWorks> swApp;

      CComBSTR sAddin(L"some path");


      swApp.CoCreateInstance(__uuidof(SldWorks), NULL, CLSCTX_LOCAL_SERVER);//launch Solidworks application, Line 1

      swApp->LoadAddIn(sAddin, &lStatus);//load Add-in, Line 2


      ...Do some works

      swApp->UnloadAddIn(sAddin, &lStatus);//unload Add-in, Line 3

      swApp->ExitApp();//exit Solidworks application, Line 4


      There is nothing wrong with the above code. However, if user close the Solidworks application between Line 2 and Line 3 manually, my application crashes. It crashes even if I don't do anything in the "Do some works" block. Can you help me how to programmatically prevent user from closing the Solidworks application and if there is no way to do so, what is the right way to clean up the Add-in and unload it before the Solidworks application is actually closed?

      I tried this test: if in Solidworks application, I unchecked the Add in (from menu) and close app manually, it didn't crashed. But I couldn't do that programmatically (I called swap->UnloadAddIn in the handler of swAppDestroyNotify, it still crashed)