156 lines
9.6 KiB
HTML
156 lines
9.6 KiB
HTML
<html>
|
|
|
|
<head>
|
|
<title>Creating Add-in Hooks (C++)</title>
|
|
<meta name=MS-HKWD content="Add-ins, hooks">
|
|
<meta name=MS-HKWD content="Hooks">
|
|
<meta name=MS-HKWD content="C++, add-ins">
|
|
<meta http-equiv="Content-Language" content="en-us">
|
|
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
|
|
<link rel="stylesheet" type="text/css" href="ApiHelp.css">
|
|
<style>
|
|
<!--
|
|
div.Section1
|
|
{page:Section1;}
|
|
-->
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<h1><span style="font-weight: normal; font-size: 7.5pt;">SOLIDWORKS PDM Professional API Help</span></h1>
|
|
<h1>Creating Add-in Hooks (C++)</h1>
|
|
<div class=Section1>
|
|
|
|
<p><span lang=EN-US style='font-family:Verdana'>This
|
|
topic shows how to implement
|
|
<a href="EPDM.Interop.epdm~EPDM.Interop.epdm.IEdmAddIn5~GetAddInInfo.html"> IEdmAddIn5::GetAddInInfo</a>
|
|
and <a href="EPDM.Interop.epdm~EPDM.Interop.epdm.IEdmAddIn5~OnCmd.html"> IEdmAddIn5::OnCmd</a>
|
|
in your add-in to have SOLIDWORKS PDM Professional notify your add-in
|
|
whenever a file is added, checked out, or checked in.</span><span class=GramE><span lang=EN-US style="FONT-FAMILY: Verdana">
|
|
|
|
|
|
</span></span></p>
|
|
<ol>
|
|
<li class="kadov-P"><span style="font-family: Verdana">C</span><span lang=EN-US style='font-family:Verdana'>all
|
|
<a href="EPDM.Interop.epdm~EPDM.Interop.epdm.IEdmCmdMgr5~AddHook.html">IEdmCmdMgr5::AddHook</a> 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:</span></li>
|
|
|
|
<blockquote>
|
|
<P><SPAN class=SpellE><SPAN class=GramE>
|
|
<SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New; mso-ansi-language:EN-US">STDMETHOD(GetAddInInfo)(EdmAddInInfo * poInfo, IEdmVault5 * poVault, IEdmCmdMgr5 * poCmdMgr)<br>{<br>
|
|
<font color=green>//The AFX_MANAGE_STATE macro is needed for MFC applications but should not
|
|
<br> //be used for applications that are MFC-free</font><br> AFX_MANAGE_STATE(AfxGetStaticModuleState());<br>
|
|
<br> if (poInfo == NULL || poCmdMgr == NULL )<br> return E_POINTER;<br>
|
|
<br> <font color=green>//Return information to the Administrate Add-ins dialog box</font><br> poInfo->mbsAddInName= SysAllocString( L"My first add-in" );<br> poInfo->mbsCompany = SysAllocString( L"The name of my company" );<br> poInfo->mbsDescription= SysAllocString( L"This is a very nice add-in." );<br> poInfo->mlAddInVersion = 1;<br>
|
|
<br> <font color=green>//SOLIDWORKS PDM Professional 5.2 is
|
|
required to install this add-in</font><br> poInfo->mlRequiredVersionMajor = 5;<br> poInfo->mlRequiredVersionMinor= 2;<br>
|
|
<br> <font color=green>//Notify when a file has been added</font><br> poCmdMgr->AddHook( EdmCmd_PostAdd, NULL );<br>
|
|
<font color=green>//Notify when a file has been checked out<br></font> poCmdMgr->AddHook( EdmCmd_PostLock, NULL );<br>
|
|
<font color=green>//Notify when a file is about to be checked in<br></font> poCmdMgr->AddHook( EdmCmd_PreUnlock, NULL );<br>
|
|
<font color=green>//Notify when a file has been checked in<br></font> poCmdMgr->AddHook( EdmCmd_PostUnlock, NULL );<br>
|
|
<br> return S_OK;<br>}</SPAN></SPAN></SPAN></P>
|
|
</blockquote>
|
|
|
|
<li class="kadov-P">
|
|
<P style="BACKGROUND: white"><span style="font-family: Verdana">Implement
|
|
IEdmAddIn5::</span><span lang=EN-US style='font-family:Verdana'>OnCmd in
|
|
your add-in as follows:</span></P></li>
|
|
|
|
<blockquote>
|
|
<P style="BACKGROUND: white"><SPAN class=SpellE>
|
|
<SPAN lang=EN-US
|
|
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">
|
|
<SPAN lang=EN-US
|
|
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US">
|
|
<o:p>STDMETHOD(OnCmd)(EdmCmd * poCmd, SAFEARRAY * * ppoData)<br>{<br>
|
|
<font color=green>//The AFX_MANAGE_STATE macro is needed for MFC applications but should not
|
|
<br> //be used for applications that are MFC-free</font><br> AFX_MANAGE_STATE(AfxGetStaticModuleState());<br>
|
|
<br> if (poCmd == NULL ||ppoData == NULL)<br> return E_POINTER;<br>
|
|
<br> <font color=green> //Check the type of hook that triggered
|
|
this call</font><br> CString oName;<br> switch(poCmd->meCmdType )<br> {<br> case EdmCmd_PostAdd: oName =
|
|
"PostAdd"; break;<br> case EdmCmd_PostLock: oName = "PostLock"; break;<br> case EdmCmd_PreUnlock: oName = "PreUnlock"; break;<br> case EdmCmd_PostUnlock: oName = "PostUnlock"; break;<br> default: oName = "?"; break;<br> }<br>
|
|
<br> <font color=green> //Obtain a pointer to the array data</font><br> if( SafeArrayGetDim( *ppoData ) != 1 )<br> return E_INVALIDARG;<br>
|
|
<br> EdmCmdData *poElements = NULL;<br> HRESULT hRes =
|
|
SafeArrayAccessData( *ppoData, (void**)&poElements );<br> if( FAILED(hRes) )<br> return hRes;<br>
|
|
<br> <font color=green> //Append the paths of all files to a string</font><br> CString oMessage =
|
|
"The following files were affected by a " + oName + " hook:\n";<br> int iCount=(*ppoData)->rgsabound->cElements;<br> for( int i =
|
|
0; i < iCount; ++i )<br> { <br> oMessage += (LPCTSTR)bstr_t(poElements->mbsStrData1 );<br> oMessage += "\n";<br> ++poElements;<br> }<br>
|
|
<br> <font color=green> //Release the array data and display a message to the user</font><br> SafeArrayUnaccessData( *ppoData );<br>
|
|
<br> MessageBox((HWND)poCmd->mlParentWnd, oMessage, "SOLIDWORKS PDM Professional", MB_OK );
|
|
<br> return S_OK;<br>}<br>
|
|
</o:p></SPAN></SPAN></SPAN></P>
|
|
|
|
<p style='background:white'><span lang=EN-US style='font-family:Verdana'>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 <a href="EPDM.Interop.epdm~EPDM.Interop.epdm.EdmCmd.html">EdmCmd</a> structure
|
|
that is passed as poCmd in OnCmd. meCmdType contains an EdmCmdType constant that
|
|
indicates the triggering hook.<o:p></o:p></span></p>
|
|
|
|
<p style='background:white'><span lang=EN-US style='font-family:Verdana'>The second argument to OnCmd
|
|
is an array of <a href="EPDM.Interop.epdm~EPDM.Interop.epdm.EdmCmdData.html">EdmCmdData</a> 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.<o:p></o:p></span></p>
|
|
|
|
|
|
</blockquote>
|
|
</P>
|
|
|
|
<p class=MsoNormal style="BACKGROUND: white"><span lang=EN-US style="FONT-SIZE:
|
|
10pt; FONT-FAMILY: Arial"><o:p><SPAN lang=EN-US
|
|
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p></o:p></SPAN></o:p></span> </p>
|
|
|
|
<li class="kadov-P">
|
|
<P style="BACKGROUND: white">
|
|
<span style="background-position: 0 0"><font face="Verdana">B</font></span><font face="Verdana"><span lang=EN-US>uild
|
|
the add-in DLL and</span></font><span lang=EN-US><font face="Verdana">
|
|
</font></span><span style="font-family: Verdana" lang="en-gb">a</span><span lang=EN-GB
|
|
style='font-family:Verdana;mso-ansi-language:EN-GB'>dd it to the file vault
|
|
using the</span><font face="Verdana"><span lang=EN-GB style='mso-ansi-language:EN-GB'>
|
|
</span></font>
|
|
<span lang=EN-GB style='font-family:Verdana;mso-ansi-language:EN-GB'>
|
|
<a href="AdminDlg.htm">Administration tool</a></span><span lang=EN-US><font face="Verdana">.</font></span></P>
|
|
</li>
|
|
<li class="kadov-P">
|
|
<P style="BACKGROUND: white">
|
|
<span style="background-position: 0 0"><font face="Verdana">T</font></span><span lang=EN-US><font face="Verdana">ry adding, checking out, and checking in
|
|
vault files.</font><o:p></o:p></span></P></li>
|
|
</ol>
|
|
<P style="BACKGROUND: white"><SPAN lang=EN-US
|
|
style="FONT-FAMILY: Verdana"><o:p><STRONG>NOTE: </STRONG></o:p></SPAN>
|
|
<span
|
|
lang=EN-US style='font-family:Verdana'>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 <a href="EPDM.Interop.epdm~EPDM.Interop.epdm.EdmCmdType.html"> EdmCmdType.EdmCmd_PreUndoLock</a> and
|
|
<a href="EPDM.Interop.epdm~EPDM.Interop.epdm.EdmCmdType.html">EdmCmdType.EdmCmd_PostUndoLock</a>
|
|
to your add-in's GetAddInInfo.</span></P>
|
|
|
|
</div>
|
|
<h2 style="background-image: url(''); background-repeat: repeat; background-attachment: scroll">
|
|
<span style="font-family: Verdana">See Also</span></h2>
|
|
<p class="MsoNormal" style="background-image: url(''); background-repeat: repeat; background-attachment: scroll">
|
|
<span class=GramE>
|
|
<span lang=EN-US style="FONT-FAMILY: Verdana">
|
|
|
|
<A href="cppaddin.htm">Creating Add-ins (C++)</A>
|
|
|
|
|
|
</span></span></p>
|
|
<p class="MsoNormal" style="background-image: url(''); background-repeat: repeat; background-attachment: scroll">
|
|
<span class=GramE>
|
|
<span lang=EN-US style="FONT-FAMILY: Verdana">
|
|
|
|
<A href="vbreactor.htm">Creating Add-in Hooks (VB.NET)</A>
|
|
|
|
|
|
</span></span></p>
|
|
</body>
|
|
</html>
|
|
|