In this sample, Melody modified the proxy to include an entry point for the CDocDrawing class (the CDocDrawing class was also modified to include events which become disassociated with ProxyGen- see this blog for related info on this bug) and the HostItemProvider to expose the CDocDrawing type. Melody also created a template for document level add-ins and used the template to create a sample add-in, ShapeAppMFCDocAddIn1.
To use this sample:
1) Remove the old proxy from the GAC by deleting or uninstalling C:\Windows\assembly\Proxy
2) Remove any VSTA v 1 add-in assemblies by deleting %MyDocuments%\ShapeAppMFC
3) Run the included setup file to register the host and updated templates (SetupShapeAppAdvancedMFC.js)
4) Build the ShapeAppAdvancedMFC.sln solution, this includes the document level sample add-in. This will register the updated proxy in the GAC and build the add-in assembly.
5) Run the sample and notice the message box and shape added from the document level add-in.
Here are the changes I made to add this functionality:
1) HostItemProvider
Unchanged code excluded
internal class HostItemProvider : IHostItemProvider
{
public HostItemProvider(ShapeApp.Proxy.Application application)
{
//SUMMIT- add drawing level HIP
//store the active drawing
this.drawing = application.ActiveDrawing;
}
public object GetHostObject(Type primaryType, string primaryCookie)
{
//Check if primaryType is supported.
else if (primaryType == typeof(ShapeApp.Proxy.CDrawingDoc))
{
//SUMMIT- add drawing level HIP
// update the drawing to ensure the current active drawing is returned
this.drawing = application.ActiveDrawing;
return this.drawing;
}
}
//SUMMIT- add drawing level HIP
//store the active drawing
private ShapeApp.Proxy.CDrawingDoc drawing;
}
2) Proxy and descriptor file
Descriptor file:
<Class originalFullyQualifiedName="ShapeApp.Proxy.CDrawingDoc" GUID="6CBD1873-21F4-4386-B9BA-62555B7BCC12" SourceInterfaceGUID="CB42B8DA-44B1-4AAA-AFCC-7AFF84A5A481" isExcluded="false" isAddInEntryPoint="true">
Proxy File:
public partial class CDrawingDocEntryPoint : global::Microsoft.VisualStudio.Tools.Applications.Runtime.IExtendedEntryPoint
{/*entry point class code*/}
3) Template
AppAddIn.designer.xml:
hostitem:baseType="ShapeApp.Proxy.CDrawingDocEntryPoint"
misc changes to vstemplate file for updated project name and description
4) Add-in
No code changes required based on updated template, here is the code from the add-in
private void AppAddIn_Startup(object sender, EventArgs e)
{
System.Windows.Forms.MessageBox.Show("Document level add-in loaded");
this.Shapes.Add(this.Application.AvailableShapes[0].Clone());
}