Initial Commit of the PDM project (ready for DWS migration)
This commit is contained in:
297
documentation/api_extracted/cppaddin.htm
Normal file
297
documentation/api_extracted/cppaddin.htm
Normal file
@@ -0,0 +1,297 @@
|
||||
<html xmlns:v="urn:schemas-microsoft-com:vml"
|
||||
xmlns:o="urn:schemas-microsoft-com:office:office"
|
||||
xmlns:w="urn:schemas-microsoft-com:office:word"
|
||||
xmlns="http://www.w3.org/TR/REC-html40">
|
||||
|
||||
<head>
|
||||
<title>Creating Add-ins (C++)</title>
|
||||
<meta name=MS-HKWD content="C++">
|
||||
<meta name=MS-HKWD content="C++,add-ins">
|
||||
<meta name=MS-HKWD content="Add-ins, C++">
|
||||
<meta name=MS-HKWD content="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">
|
||||
</head>
|
||||
|
||||
<h1><span style="font-weight: normal; font-size: 7.5pt;">SOLIDWORKS PDM Professional API Help</span>
|
||||
</h1>
|
||||
<h1>Creating Add-ins (C++)</h1>
|
||||
|
||||
<body bgcolor=white lang=SV link=blue vlink=purple style='tab-interval:65.2pt'>
|
||||
|
||||
<div class=Section1>
|
||||
|
||||
<p><span lang=EN-US style='font-family:Verdana'>This topic shows how to create
|
||||
an add-in using Visual C++ in Microsoft Visual Studio
|
||||
that adds a menu item to the context-sensitive and Tools menus of vaults in File Explorer. You must be familiar
|
||||
with the process of creating a C++ COM DLL in the development environment that
|
||||
you use.</span></p>
|
||||
|
||||
<ol>
|
||||
<li class="kadov-P"><font face="Verdana" style="font-size: 8pt">
|
||||
<span lang=EN-US style='mso-ansi-language:EN-US'>Create the C++ project.<br>
|
||||
</span></font><ol>
|
||||
<li><font face="Verdana" style="font-size: 8pt">
|
||||
<span lang=EN-US style='mso-ansi-language:EN-US'>Start Microsoft Visual
|
||||
Studio.<br> </span></font></li>
|
||||
<li><span lang="en-us"><font face="Verdana">Select <b>File >
|
||||
New > Project > Visual C++ > <span lang="sv">MFC/</span>ATL > ATL Project</b>.<br> </font></span></li>
|
||||
<li><font face="Verdana" style="font-size: 8pt">
|
||||
<span lang=EN-US style='mso-ansi-language:EN-US'>Type the name of your
|
||||
project in <b>Name</b>.<br> </span></font></li>
|
||||
<li><span lang="en-us"><font face="Verdana">Click <b>Browse</b> and navigate to the folder where to create your project.<br> </font></span></li>
|
||||
<li><span lang="en-us"><font face="Verdana">Click <b>OK</b>.<br> </font></span></li>
|
||||
<li>
|
||||
<p class=MsoNormal>If you intend on using MFC, select <b>Application
|
||||
Settings</b> > <b>Support MFC</b> in the ATL Project Wizard dialogMyAdd.<br> </p>
|
||||
</li>
|
||||
<li>
|
||||
<p class=MsoNormal>Click
|
||||
<strong>Finish</strong> to generate the
|
||||
project. <br> </p></li>
|
||||
</ol>
|
||||
|
||||
</li>
|
||||
<li class=kadov-p>
|
||||
<p class=MsoNormal>Modify the project's settings.</p>
|
||||
|
||||
<ol>
|
||||
<li>
|
||||
<p class=MsoNormal>Right-click the project in Solution Explorer, and select
|
||||
<b>Add > Class</b>.<br> </p></li>
|
||||
<li>
|
||||
<p class=MsoNormal>In the Add Class dialog, select <strong>ATL > ATL Simple
|
||||
Object</strong>.<br> </p></li>
|
||||
<li>
|
||||
<p class=MsoNormal>Click <b>Add</b>.<br> </p></li>
|
||||
<li>
|
||||
<p class=MsoNormal>Type <b>MyAddIn</b> in <b>Short name</b>.<br> </p>
|
||||
</li>
|
||||
<li>
|
||||
<p class=MsoNormal>Click <b>Next </b>and<b> Next</b>.<br> </p></li>
|
||||
<li>
|
||||
<p class=MsoNormal>Select
|
||||
<b>Custom</b> in the Interface and <strong>Both</strong> in the Threading
|
||||
Model.<br> </p></li>
|
||||
<li>
|
||||
<p class=MsoNormal>Click <b>Finish</b>. <br> </p></li>
|
||||
<li>
|
||||
<p class="MsoNormal">Select <b>View > Class View</b> and expand your project in the Class View window.<br> </p>
|
||||
</li>
|
||||
<li>
|
||||
<p class="MsoNormal">Right-click <b>CMyAddIn</b> and select<b> Add >
|
||||
Implement Interface</b>.
|
||||
<br> </p></li>
|
||||
<li>
|
||||
<p class=MsoNormal>Select <b>Project</b> and select the most recent SOLIDWORKS PDM Professional type library,
|
||||
<b>Edm.tlb</b>, from
|
||||
the <b>Available type libraries</b> list.
|
||||
<br><br /><b>NOTE:</b> If the type library is not in the list, you must
|
||||
copy <b>Edm.tlb</b> from the API folder on the CD to <i>project_path\project_name\project_name</i>.
|
||||
Then select <b>File</b>, browse to <i>project_path\project_name\project_name, </i>
|
||||
and select <b>Edm.tlb</b>.<br> </p></li>
|
||||
<li>
|
||||
<p class=MsoNormal>Select
|
||||
<a href="EPDM.Interop.epdm~EPDM.Interop.epdm.IEdmAddIn5.html">IEdmAddIn5</a>
|
||||
in <b>Interfaces</b> .<br> </p></li>
|
||||
<li>
|
||||
<p class=MsoNormal>Click the single right-arrow button to move IEdmAddIn5 to
|
||||
<b>Implement Interfaces</b>, and click <b>Finish</b>.
|
||||
<br>
|
||||
<br>
|
||||
Two
|
||||
new methods,
|
||||
<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>,
|
||||
are added to your class.</p></li>
|
||||
<li>
|
||||
<p class=MsoNormal>Select <strong>File > Save All</strong>.<br> </p>
|
||||
</li>
|
||||
</ol>
|
||||
|
||||
</li>
|
||||
<li class=kadov-p>
|
||||
<p class=MsoNormal>Implement
|
||||
IEdmAddIn5::GetAddInInfo by replacing <font size="2" face="Courier New">
|
||||
STDMETHOD(GetAddInInfo)</font>in <b>MyAddin.h</b> with the following code.<br><br>
|
||||
<span lang=EN-US
|
||||
style='font-size:10.0pt;font-family:"Courier New"'>STDMETHOD(GetAddInInfo)(EdmAddInInfo
|
||||
* poInfo, IEdmVault5 * poVault, IEdmCmdMgr5 * poCmdMgr)<br>{<br>
|
||||
<span style='color:green'>//The AFX_MANAGE_STATE macro is needed
|
||||
for MFC applications but should not <br>//be used for applications that are MFC-free</span><br> AFX_MANAGE_STATE(AfxGetStaticModuleState());<br>
|
||||
<br> if (poInfo == NULL || poCmdMgr == NULL )<br> return E_POINTER;<br>
|
||||
<br> <span style='color:green'>//Return some information
|
||||
to the Properties dialog box</span><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>
|
||||
<span style='color:green'>//SOLIDWORKS PDM Professional 5.2 is
|
||||
required by this add-in</span><br> poInfo->mlRequiredVersionMajor = 5;<br> poInfo->mlRequiredVersionMinor= 2;<br>
|
||||
<br> <span style='color:green'>//Add hooks and menu commands to
|
||||
SOLIDWORKS PDM Professional<br> //Below is a menu command that
|
||||
appears in the Tools<br> //and context-sensitive menus of a
|
||||
vault in File Explorer </span><br> poCmdMgr->AddCmd( 1, bstr_t("My first menu
|
||||
command"), EdmMenu_Nothing, bstr_t(""), bstr_t(""),
|
||||
0, 0 );<br><br> return S_OK;<br>}</span></p></li>
|
||||
<li class=kadov-p>
|
||||
<p>Implement IEdmAddIn5::OnCmd by replacing
|
||||
<font size="2" face="Courier New">STDMETHOD(OnCmd)</font>in <b>MyAddin.h</b>
|
||||
with the following code.</span><br><br>
|
||||
<span lang=EN-US
|
||||
style='font-size:10.0pt;font-family:"Courier New"'>STDMETHOD(OnCmd)(EdmCmd *
|
||||
poCmd, SAFEARRAY * * ppoData)<br>{<br><span style='color:green'>//The AFX_MANAGE_STATE macro is needed
|
||||
for MFC applications, but should not <br>//be used for applications that are MFC-free</span><br> AFX_MANAGE_STATE(AfxGetStaticModuleState());<br>
|
||||
<br> if (poCmd == NULL ||ppoData == NULL)<br> return E_POINTER;<br>
|
||||
<br> MessageBox((HWND)poCmd->mlParentWnd, L"Hello
|
||||
World!", L"SOLIDWORKS PDM Professional", MB_OK );<br><br> return S_OK;<br>}<br>
|
||||
<br>
|
||||
</span><span style="font-weight: 700" lang="en-us"><font face="Verdana">NOTE</font></span><font face="Verdana"><span lang=EN-US><b>:</b>
|
||||
If you copy the code from this topic and paste it into the IDE, delete any characters or spaces that offend the
|
||||
compiler. On a 64-bit computer, you must replace <b>L</b>
|
||||
with <b>bstr_t()</b> for the strings in the MessageBox.<br> </span></font></p></li>
|
||||
<li class=kadov-p>
|
||||
<p class=MsoNormal>Specify the project configuration properties:</p>
|
||||
|
||||
<ol>
|
||||
<li>
|
||||
<p class=MsoNormal>Right-click the project name in Solution Explorer and
|
||||
select <b>Properties</b>.</p></li>
|
||||
<li>
|
||||
<p class=MsoNormal>Select <b>Configuration Properties > General</b>.<br>
|
||||
<br>
|
||||
Ensure that the properties are configured as:</p>
|
||||
<ul>
|
||||
<li>
|
||||
<p class=MsoNormal>Output Directory:
|
||||
<b>$(SolutionDir)$(Platform)\$(Configuration)\</b></p></li>
|
||||
<li>
|
||||
<p class=MsoNormal>Configuration Type: <b>Dynamic Library (.dll)</b></p></li>
|
||||
<li>
|
||||
<p class=MsoNormal>Use of MFC: <b>Use MFC in a Shared DLL</b></p></li>
|
||||
<li>
|
||||
<p class=MsoNormal>Use of ATL:<b> Dynamic Link to ATL</b></p></li>
|
||||
<li>
|
||||
<p class=MsoNormal>Character Set: <b>Use Unicode Character Set</b></p></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<p class=MsoNormal>Select <b>Linker > General</b>.<br>
|
||||
<br>
|
||||
Ensure Output File is:</p>
|
||||
<ul>
|
||||
<li>
|
||||
<p class=MsoNormal> <b>$(SolutionDir)$(Platform)\$(Configuration)\$(TargetName)$(TargetExt)</b></p>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<p class=MsoNormal>Select <b>Linker > Input</b>.<br><br>Ensure that Module Definition File is
|
||||
<b>.\</b><i>project_name</i><b>.def</b>.</p></li>
|
||||
<li>
|
||||
<p class=MsoNormal>Select <b>Linker > Embedded IDL</b>.<br><br>Ensure the properties are configured as follows:</p>
|
||||
<ul>
|
||||
<li>
|
||||
<p class=MsoNormal>Type Library:
|
||||
<b>$(SolutionDir)$(Platform)\$(Configuration)\$(ProjectName).tlb</b></p>
|
||||
</li>
|
||||
<li>
|
||||
<p class=MsoNormal>TypeLib Resource ID should be empty. Delete any
|
||||
characters appearing in this row.</p></li>
|
||||
</ul></li>
|
||||
<li>
|
||||
<p class=MsoNormal>Select <b>MIDL > General</b>.<br><br>Select the environment in the Target Environment<i>
|
||||
</i>dropdown that
|
||||
most closely matches your environment.</p></li>
|
||||
<li>
|
||||
<p class=MsoNormal>Select <b>MIDL > Output</b>.<br><br>Ensure the properties are configured as follows:</p>
|
||||
<ul>
|
||||
<li>
|
||||
<p class=MsoNormal>Output Directory:
|
||||
<b>$(SolutionDir)$(Platform)\$(Configuration)\</b></p></li>
|
||||
<li>
|
||||
<p class=MsoNormal>Type Library: <b>$(IntDir</b><i>)project_name.</i><b>tlb</b></p></li>
|
||||
</ul></li>
|
||||
</ol></li>
|
||||
<li class=kadov-p>
|
||||
<p class=MsoNormal>Click <b>OK</b>.</p></li>
|
||||
<li class=kadov-p>
|
||||
<p class=MsoNormal>To change the project's type of configuration to <b>
|
||||
Release</b>:</p>
|
||||
|
||||
<ol>
|
||||
<li>
|
||||
<p class=MsoNormal>In the Solution Explorer, right-click <b>Solution </b>'<i>project_name</i>'<b> </b>
|
||||
and select <b>Configuration Manager.</b></p></li>
|
||||
<li>
|
||||
<p class=MsoNormal>Click the down-arrow key in the project's Configuration
|
||||
column and select <b>Release. </b></p></li>
|
||||
<li>
|
||||
<p class=MsoNormal>Click<b> Close</b>.</p></li>
|
||||
</ol></li>
|
||||
<li class=kadov-p>
|
||||
<p class=MsoNormal>Save and compile
|
||||
the project for either x32 or x64 to create an add-in DLL that is compatible
|
||||
with your system. <br><br><span style="font-family: Verdana" lang="en-us">
|
||||
<b>NOTE</b>: See <a href="Using_NET_Framework_in_Addins.htm">Using .NET Framework in Add-in Applications</a>
|
||||
if a problem occurs at runtime.</span><br> </p></li>
|
||||
<li class=kadov-p>
|
||||
<p class=MsoNormal>Add the new add-in, <i>project_name</i><b>.dll</b>, to
|
||||
the file vault:<span lang=EN-US style='mso-ansi-language:EN-US'><br> </span></p>
|
||||
<ol style="font-family: Verdana; font-size: 8pt">
|
||||
<li><span lang=EN-US style='mso-ansi-language:EN-US'>Start up the SOLIDWORKS
|
||||
PDM Professional <a href="AdminDlg.htm">Administration tool</a>.<br> </span></li>
|
||||
<li><span lang=EN-US style='mso-ansi-language:EN-US'>Expand the vault where
|
||||
you want to install this add-in. Log in, if prompted.<br> </span></li>
|
||||
<li><span lang="en-us">Right-click <b>Add-ins</b> and select <b>New
|
||||
Add-in</b>.<br> </span></li>
|
||||
<li><span lang="en-us">Select:<br>
|
||||
</span><ul style="font-family: Verdana; font-size: 8pt">
|
||||
<li><span lang="en-us">x32: </span>
|
||||
<span lang=EN-US style='mso-ansi-language:EN-US'>
|
||||
<i style='mso-bidi-font-style:
|
||||
normal'>project_path</i><span style='mso-bidi-font-style:
|
||||
normal; '><i>\</i></span></span><span style='mso-bidi-font-style:
|
||||
normal; mso-ansi-language:EN-US' lang="EN-US"><i>project_name\</i><b>Release</b><i>\project_name</i><b>.dll</b>, and click
|
||||
<b>Open</b>.<br>
|
||||
</span></li>
|
||||
<li><span lang="en-us">x64: </span>
|
||||
<span lang=EN-US style='mso-ansi-language:EN-US'>
|
||||
<i style='mso-bidi-font-style:
|
||||
normal'>project_path</i><span style='mso-bidi-font-style:
|
||||
normal; '><i>\</i></span></span><span style='mso-bidi-font-style:
|
||||
normal; mso-ansi-language:EN-US' lang="EN-US"><i>project_name\</i><b>x64</b><i>\</i><b>Release</b><i>\project_name</i><b>.dll</b>, and click
|
||||
<b>Open</b>.<br><br>The add-in <b>Properties</b> dialog displays the add-in's name,
|
||||
company, add-in version, required version of SOLIDWORKS PDM Professional,
|
||||
package, and description.<br> </span></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><span lang="en-us">Click <b>OK</b>.</span></li>
|
||||
</ol>
|
||||
<p class=MsoNormal> </p></li>
|
||||
<li class=kadov-p>
|
||||
<p class=MsoNormal>Right-click the list of vaults in File Explorer to
|
||||
show the context menu:<br><br>
|
||||
<img
|
||||
border=0 width=166 height=298 id="_x0000_i1034" src=contextmenu.gif><br>The new menu item appears in the context menu.<br> </p></li>
|
||||
<li class=kadov-p>
|
||||
<p class=MsoNormal>Select <b>My first menu command</b> on the context-sensitive
|
||||
menu.<br>
|
||||
</p></li>
|
||||
<li class=kadov-p>
|
||||
<p class=MsoNormal>A message box is displayed.<br></span></p></li>
|
||||
</ol>
|
||||
|
||||
<p>Use
|
||||
your new add-in to
|
||||
create <a href="cppmenuitem.htm">more advanced menu commands</a> or
|
||||
<a href="cppreactor.htm">add-in hooks</a> that allow you to check files in and out of the vault.</p>
|
||||
|
||||
<p class=MsoNormal style='background:white'><span lang=EN-GB style='font-size:
|
||||
10.0pt;font-family:Arial;mso-ansi-language:EN-GB'><o:p> </o:p></span></p>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user