Hide Table of Contents

Creating Add-in Hooks (C++)

This topic shows how to implement IEdmAddIn5::GetAddInInfo and IEdmAddIn5::OnCmd in your add-in to have SOLIDWORKS PDM Professional notify your add-in whenever a file is added, checked out, or checked in.

  1. Call IEdmCmdMgr5::AddHook from your add-in's GetAddInInfo method for each activity you want your add-in to know about. Implement IEdmAddIn5::GetAddInInfo in your add-in as follows:
  2. STDMETHOD(GetAddInInfo)(EdmAddInInfo * poInfo, IEdmVault5 * poVault, IEdmCmdMgr5 * poCmdMgr)
    {
       //The AFX_MANAGE_STATE macro is needed for MFC applications but should not
       //be used for applications that are MFC-free

       AFX_MANAGE_STATE(AfxGetStaticModuleState());

       if (poInfo == NULL || poCmdMgr == NULL )
         return E_POINTER;

       //Return information to the Administrate Add-ins dialog box
       poInfo->mbsAddInName= SysAllocString( L"My first add-in" );
       poInfo->mbsCompany = SysAllocString( L"The name of my company" );
       poInfo->mbsDescription= SysAllocString( L"This is a very nice add-in." );
       poInfo->mlAddInVersion = 1;

       //SOLIDWORKS PDM Professional 5.2 is required to install this add-in
       poInfo->mlRequiredVersionMajor = 5;
       poInfo->mlRequiredVersionMinor= 2;

       //Notify when a file has been added
       poCmdMgr->AddHook( EdmCmd_PostAdd, NULL );
       //Notify when a file has been checked out
       poCmdMgr->AddHook( EdmCmd_PostLock, NULL );
       //Notify when a file is about to be checked in
       poCmdMgr->AddHook( EdmCmd_PreUnlock, NULL );
       //Notify when a file has been checked in
       poCmdMgr->AddHook( EdmCmd_PostUnlock, NULL );

       return S_OK;
    }

  3. Implement IEdmAddIn5::OnCmd in your add-in as follows:

  4. STDMETHOD(OnCmd)(EdmCmd * poCmd, SAFEARRAY * * ppoData)
    {
       //The AFX_MANAGE_STATE macro is needed for MFC applications but should not
       //be used for applications that are MFC-free

       AFX_MANAGE_STATE(AfxGetStaticModuleState());

       if (poCmd == NULL ||ppoData == NULL)
         return E_POINTER;

       //Check the type of hook that triggered this call
       CString oName;
       switch(poCmd->meCmdType )
       {
         case EdmCmd_PostAdd: oName = "PostAdd"; break;
         case EdmCmd_PostLock: oName = "PostLock"; break;
         case EdmCmd_PreUnlock: oName = "PreUnlock"; break;
         case EdmCmd_PostUnlock: oName = "PostUnlock"; break;
         default: oName = "?"; break;
       }

       //Obtain a pointer to the array data
       if( SafeArrayGetDim( *ppoData ) != 1 )
         return E_INVALIDARG;

       EdmCmdData *poElements = NULL;
       HRESULT hRes = SafeArrayAccessData( *ppoData, (void**)&poElements );
       if( FAILED(hRes) )
         return hRes;

       //Append the paths of all files to a string
       CString oMessage = "The following files were affected by a " + oName + " hook:\n";
       int iCount=(*ppoData)->rgsabound->cElements;
       for( int i = 0; i < iCount; ++i )
       {
         oMessage += (LPCTSTR)bstr_t(poElements->mbsStrData1 );
         oMessage += "\n";
         ++poElements;
       }

       //Release the array data and display a message to the user
       SafeArrayUnaccessData( *ppoData );

       MessageBox((HWND)poCmd->mlParentWnd, oMessage, "SOLIDWORKS PDM Professional", MB_OK );
       return S_OK;
    }
     

    OnCmd is called for each of the hooks registered in GetAddInInfo. You can tell which hook triggered the call by inspecting the meCmdType member of the EdmCmd structure that is passed as poCmd in OnCmd. meCmdType contains an EdmCmdType constant that indicates the triggering hook.

    The second argument to OnCmd is an array of EdmCmdData structures. There is one element in the array for each file that is affected by the call. The contents of the structure members vary depending on the type of hook that triggers the call. See EdmCmdData for a complete list of members and their descriptions.

     

  5. Build the add-in DLL and add it to the file vault using the Administration tool.

  6. Try adding, checking out, and checking in vault files.

NOTE: OnCmd is not called during check-in if the file is not modified before it is checked in. During check-in of unmodified files, SOLIDWORKS PDM Professional triggers an "undo check-out" event. To handle this "undo check-out" event, add hooks for EdmCmdType.EdmCmd_PreUndoLock and EdmCmdType.EdmCmd_PostUndoLock to your add-in's GetAddInInfo.

See Also

Creating Add-ins (C++)

Creating Add-in Hooks (VB.NET)



Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Creating Add-in Hooks (C++)
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:



x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2018 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.