Finally an easy one

Latest post 04-28-2008 10:25 AM by Melody. 17 replies.
  • 04-16-2008 12:15 PM

    • Terry
    • Top 10 Contributor
    • Joined on 05-10-2006
    • Posts 90

    Finally an easy one

    I don't know if this qualifies as a Tech discussion, but I hope so.  I'm trying to finalize my design for integrating VSTA into an application and am struggling with some of the terminology and how these items relate to each other.  If there's another thread that covers this, please let me know.  I've read just about all the SDK docs and looked at the Glossary but it leaves out a number of conceptual items.  I'll just list questions randomly and see where that leads:

    1) Is a single AddIn equal to a single .dll or is a single AddIn equal to a single Host Item?  Meaning if I'm going to load multiple Addin's for an application, what does that mean in the physical world in terms of what I'm really doing and how I keep them seperate.

    2) Does a single HostItem (HostID in the registry) equal a single Class File in an AddIn Project? I'm assuming I know the answer to this is Yes, but just to confirm before the next question.

    3) Does every HostItem have to have an Entry point in the Proxy?  What I'm driving at here is the idea that it seems I need to have one, primary Host Item with an entry point that is always the focal point of the DTE when I open it up.  I know I'm supposed to be able to add more HostItem's after, but what if I'm not always creating the same HostItem first?  Is the idea here that I can load the DTE and first project around any HostItem with an Entry Point, or just any HostItem that's in the registry?

    4) What's the deal with all this Application-level and Document-level talk?  Is there really different types of AddIns or is this just a way of talking about how you can use an AddIn and when it's loaded?  I don't see anything that indicates that an AddIn needs to represent any particular object, or loaded and any particular time.  Of course, not knowing the answer to #1 makes this hard to understand...

    This all revolves around the issues I'm having with how to interact with the DTE and loading projects, adding Host Items and Objects, what to name them, etc.  For example, if I register a HostID called "Drawing" and pass that HostID to the Provider.GetDTE(), what have I committed to since I haven't loaded the project yet?  Of course in the very next step I'm loading a project for that same HostID but is that just a coincicence?  Can I create the DTE using one HostID and then never load a project for that HostID?  Can I Load a DTE and then arbitrarilly add and remove Projects as the user moves about the application?  This all really comes down to an understanding of how the AddIn, HostItem, Project, ClassFile, and DTE relate to each other.

    Wow, that was a mouthful.  And I held back on a number of questions hoping they would all come to me if I understood the basics more.

    Time for some Mt. Dew...

     

     

     

  • 04-16-2008 4:54 PM In reply to

    • Melody
    • Top 10 Contributor
    • Joined on 04-26-2007
    • Syracuse, NY
    • Posts 248

    Re: Finally an easy one

    Terry,

    The terminology can be confusing at first, especially since the DPM terminology overlaps the non-DPM terminology. 

    1) Is a single AddIn equal to a single .dll or is a single AddIn equal to a single Host Item?  Meaning if I'm going to load multiple Addin's for an application, what does that mean in the physical world in terms of what I'm really doing and how I keep them separate.

    A single add-in is a single dll that is loaded into the Host Application (sometimes referred to as just the Host, but not the Host Item).  If you load multiple add-ins into a Host Application, the Host Application loads each add-in's dll- the dll is locked at that time.  The add-in can be thought of in terms of its dll:  Add-in = dll = assembly.


    2) Does a single HostItem (HostID in the registry) equal a single Class File in an AddIn Project? I'm assuming I know the answer to this is Yes, but just to confirm before the next question.

    HostItem <> !=  HostID.  A the HostID is used in the registries, in the templates to specify which HostID registry, and in the Host Application when it is starting VSTA to specify which registry.  That is all that the Host ID is. 

    HostItem is a DPM concept- it is completely separate and has nothing to do with the registries.

    For normal (regular/non-DPM) add-in's the Host Item Name (3rd page ProjectGen) is used in three places:  the Startup Class in the add-in that the host looks for, the Primary Cookie in the add-in which is passed to the host, and in the host (for the startup class of the add-in).

    Is your host COM based?  COM based apps do register classes in the registries but that doesn't have anything to do with VSTA.


    3) Does every HostItem have to have an Entry point in the Proxy?  What I'm driving at here is the idea that it seems I need to have one, primary Host Item with an entry point that is always the focal point of the DTE when I open it up.  I know I'm supposed to be able to add more HostItem's after, but what if I'm not always creating the same HostItem first?  Is the idea here that I can load the DTE and first project around any HostItem with an Entry Point, or just any HostItem that's in the registry?

    The host application exposes entry points- for example the application or a document.  In (nonDPM) VSTA there is no "primary host item"; however, the ShapeAppSamples certainly use the Application class in this way.  You could offer only a Document level entry point (so "this" or "me" would be the document) and not offer an Application level (where "this" or "me" would be the application) entry point.  Any class can be an entry point.  It is easier to understand this if you look at nonDPM VSTA before you dive into DPM because the terminology overlaps.

    For DPM- the HostItem must be an entry point.  HostItems contain HostObject which do not have to be an entry point.  HostItems are a starting point that is exposed to VSTA, HostObject are simply objects in the HostItem.  You could have two different HostItems that both contain the same type of HostObjects.

    You can load the DTE and first project around any entry point, including DPM HostItems- this has nothing to do with the registries.

     


    4) What's the deal with all this Application-level and Document-level talk?  Is there really different types of AddIns or is this just a way of talking about how you can use an AddIn and when it's loaded?  I don't see anything that indicates that an AddIn needs to represent any particular object, or loaded and any particular time.  Of course, not knowing the answer to #1 makes this hard to understand...

    Application-level add-ins use the Application Entry Point.  Document-level add-ins use the Document-level Entry Point.  Because each project template only allows one entry point these add-ins are based off different templates.  Add-ins with different entry points are used differently because "this" or "me" refers to a different object.  The add-in in itself does not need to represent a particular object, but again the entry point will determine which host type and instance "me" or "this" refers to.


    >For example, if I register a HostID called "Drawing" and pass that HostID to the Provider.GetDTE(), what have I committed to since I haven't loaded the project yet?

    This is incorrect becuase HostID's are not entry points or HostItems.  When you call Provider.GetDTE you are calling it for a Host Application (see * below).

     


    >Of course in the very next step I'm loading a project for that same HostID but is that just a coincidence?

    You can only load projects (into the DTE) for a host that you have registered and passed the HostID to with Provider.GetDTE.

     


    >Can I create the DTE using one HostID and then never load a project for that HostID?  Can I Load a DTE and then arbitrarilly add and remove Projects as the user moves about the application?

    You can only load projects into the DTE that are for the HostID the DTE is for.  You can load a DTE and arbitrarily add and remove Projects that use the same HostID as the DTE.

     


    >This all really comes down to an understanding of how the AddIn, HostItem, Project, ClassFile, and DTE relate to each other.

    I need a Mt. Dew for me before I tackle that one. 

    *You can register multiple HostID's for 1 application, but this is not common and I don't think this is what you are trying to do.  If it is, I STRONGLY suggest you get everything working with 1 HostId and then determine if you really do need a second.

     

    OK- Hope this helps!  Please let me know if you have any more questions- I hope I answered more questions than I created.

    -Melody

     

  • 04-17-2008 1:22 AM In reply to

    • Terry
    • Top 10 Contributor
    • Joined on 05-10-2006
    • Posts 90

    Re: Finally an easy one

    Thanks, this will help a lot (once I've had some sleep).  I'm sure there will be a clerification question or two tomorrow but I think this will get most of the dots connected.

     

     

  • 04-18-2008 9:21 AM In reply to

    • Terry
    • Top 10 Contributor
    • Joined on 05-10-2006
    • Posts 90

    Re: Finally an easy one

    1) Ok, I think I got this one since it's easy enough.  AddIn is a DLL, which will typically be created through an AddIn project with one or more HostItem class files in it.  This would suggest that a typical simple application would load one AddIn that would have HostItems in it for the various HostIemClassFiles in the appliation (Like one application and multiple documents)

    2) This one is still fuzzy.  Are you saying that the HostID and it's related registry tree (generated by the VSTA.exe /setup command) is simply describing a DTE setup for the purposes of Creating and Opening a project template?  If this is true, then my Host ID (and the settings we put under it in the registry) seem to be related to the IDE and where it stores and retrieves it's file and information and has nothing to do with my HostItems or HostObjects.  In fact it doesn't really even seem to have any real connection to my Host Application other then the fact that when I want to open an IDE/DTE I need to tell it which HostID Entry to look under for behavioral info.

    3) Ok, so when I'm creating a DTE the first parameter I pass to the ProviderGetDTE() method is just the HostID that will be used to get the behaviroal information mentioned in #2 and doesn't imply any particular HostItem or Object Model.  In fact, not until I load a project using Solution.AddFromTemplate() do I actually start to imply the use of any particular HostItem... and that's only because I'm loading from a template that has a "Base Type" HostItem specified?

    4) So, each project template has one entry point, but once I load the project template in the IDE I can add other HostItems to the template, in addition to the one that already is in the project template.  And, this one that's in the template must have an entry point.  My confusion is around your statement about app and doc having to use different templates (which would end up being different AddIns/Dlls) because they both need their own entry point.  Couldn't I have one project template with the app HostItem specified as the entry point and then add multiple doc HostItems at run-time to achieve the same affect?

    Also I'm reading this from the SDK doco, which is using plurals to suggest that you can have multiple entry points in a project:

    "Host items in add-in projects derive from entry point classes in the proxy assembly. An entry point is a proxy type that provides direct access to an object in the object model of the host application. The entry point type is instantiated when the host application loads an add-in. Typically, the entry point is a proxy for a host type at the top of the object model hierarchy, such as an Application class."

    Maybe this is all simpler than I'm making it out to me.  Is it just that when an AddIn loads, any HostItem Classes in it with an Entry Point will be instantiated and fire their Startup events?  Then if I programmatically add some later in the same session, they won't get instantiated until the addin is re-loaded?

    5) I know this is new, but it seems important to the other points.  When I use ProjectGen, it requires me to pick a HostITem that will be the "Base Type" so it seems that Project Templates must have a HostItem in them in order to load them up.  This does't make sense because I thought an AddIn didn't have to have an particular HostItem in them.  Is this just becuase it's a template and it's not too valuable as a template without at least one HostItem clas?

     

    I'm gaining clerity... just not 20/20 yet.

    Thx.

     

     

  • 04-18-2008 10:08 AM In reply to

    • Melody
    • Top 10 Contributor
    • Joined on 04-26-2007
    • Syracuse, NY
    • Posts 248

    Re: Finally an easy one

    Terry,
    Have you done the ShapeApp samples walkthroughs in the SDK?  Doing these walkthroughs will clarify a lot of the quesitons you have about add-ins, templates, registry entries, and the IDE.  Once you have gone through the walkthroughs it will be easier to see how DPM builds on a VSTA integration instead of being in every step of it. 

    I will answer the questions you submitted, but the answers will be a lot easier to understand if you go through the walkthroughs.  Here's the help link to the walkthrough:  ms-help://MS.VSCC.v90/MS.VSIPCC.v90/MS.VSTASDK.v20/dv_vstasdk/html/a90f6be6-187a-4cec-b6f5-306211f40c24.htm

    Thanks,
      -Melody
  • 04-18-2008 11:53 AM In reply to

    • Terry
    • Top 10 Contributor
    • Joined on 05-10-2006
    • Posts 90

    Re: Finally an easy one

    I know this sounds nearly impossible, but I can't get any of the samples to run...  Oddly I've been able to build my own addin's and debug them remotely but the shape apps don't fly.  Another developer has had problems as well.  I'd have to run the process again to tell what the issues/error messages were.

    I have opened the projects and used them extensively to understand the code, but I agree that seeing it run and interacting would be a big help.  Of course, trying to understand the shape app is almost as bad as understanding VSTA....  I can't imagine a more convoluted app in which to demo the product but I'm sure it's out there.  My real issues are with the complexities of the shape app aside from the VSTA integration, which just applifies the confusion factor.

    If I get time later today (after a design meeting I'm cramming for) I'll try the sample apps again.

    Thx.

     

     

  • 04-18-2008 12:13 PM In reply to

    • Melody
    • Top 10 Contributor
    • Joined on 04-26-2007
    • Syracuse, NY
    • Posts 248

    Re: Finally an easy one

    > I know this sounds nearly impossible, but I can't get any of the samples to run

        Not at all!  The most common reason for not getting the samples to run properly is not running the setup file- each sample has its own setup file so you will need to run before using the sample.  The SDK does include instructions for this under the ShapeAppSamples section.  If running the setup file doesn't solve the problem please let me know and we'll go from there.  Are you using a 64bit machine (the setup files are not for 64 bit machines)?

    >I have opened the projects and used them extensively to understand the code, but I agree that seeing it run and interacting would be a big help.

        Stepping through the VSTA specific parts of the samples really is the difference between looking at the pieces of a jigsaw puzzle and looking at the puzzle put together.  It's also important to get them running so that we can exchange ShapeApp pieces for support.

    >Of course, trying to understand the shape app is almost as bad as understanding VSTA....  I can't imagine a more convoluted app in which to demo the product but I'm sure it's out there.  My real issues are with the complexities of the shape app aside from the VSTA integration, which just applifies the confusion factor.

        This is a common complaint- for VSTA v 1 we had simple samples that each demonstrated specific key pieces, we will get some up for VSTA v 2.  If you have a specific request, let us know- we may be able to put that on the top of the list.

    >If I get time later today (after a design meeting I'm cramming for) I'll try the sample apps again.
    We're here when you're ready.

    Good luck!
    -Melody
  • 04-18-2008 4:41 PM In reply to

    • Melody
    • Top 10 Contributor
    • Joined on 04-26-2007
    • Syracuse, NY
    • Posts 248

    Re: Finally an easy one

    Terry,
    Here are responses to your questoins.  I really suggest going through the walkthroughs before reading this because this covers some complicated DPM stuff that may be confusing and make the walkthorughs seem more confusing.  "Simple" VSTA first, then DPM.

    Hope this helps!
    -Melody


    1)  Ok, I think I got this one since it's easy enough.  AddIn is a DLL, which will typically be created through an AddIn project with one or more HostItem class files in it.  This would suggest that a typical simple application would load one AddIn that would have HostItems in it for the various HostIemClassFiles in the appliation (Like one application and multiple documents)

    > AddIn is a DLL, which will typically be created through an AddIn project

    Correct.

     

    > with one or more HostItem class files in it. 

    HostItems are only for DPM.  Add-ins do not have to be DPM. 

    All HostItems are Entry Points, but not all Entry Points are Host Items:  EntryPoint = Rectangle, HostItem = Square.  The difference between an Entry Point and a Host Item is whether it is being used within the DPM context- that is handled completely in the host.

    Templates use one Entry Point.  All projects based off this template (add-ins) use this Entry Point.  For a DPM project, a project based off a template is used and the Entry Point of that template is used as the “Host” (my term).  This “Host” Entry Point contains a collection of the Entry Point objects which are used as Host Items.  HostItems are added to it “Host”’s collection and the “Host”’s collection may contain an empty (no HostItem class file).  HostObjects are then added to the HostItems. 

     

    > This would suggest that a typical simple application would load one AddIn

    Even simple applications can load multiple add-ins.  The ShapeAppBasicCSharp sample loads and discovers multiple add-ins.

    For DPM you would (probably) want only one DPM add-in; however, you could have multiple DPM add-ins, but it would take a lot of management.  Also, you can load both nonDPM add-ins and DPM add-ins, they do not conflict with each other.

     

     


    2) This one is still fuzzy.  Are you saying that the HostID and it's related registry tree (generated by the VSTA.exe /setup command) is simply describing a DTE setup for the purposes of Creating and Opening a project template?  If this is true, then my Host ID (and the settings we put under it in the registry) seem to be related to the IDE and where it stores and retrieves it's file and information and has nothing to do with my HostItems or HostObjects.  In fact it doesn't really even seem to have any real connection to my Host Application other then the fact that when I want to open an IDE/DTE I need to tell it which HostID Entry to look under for behavioral info.

    >Are you saying that the HostID and it's related registry tree (generated by the VSTA.exe /setup command) is simply describing a DTE setup for the purposes of Creating and Opening a project template?

    Basically.

     

    >If this is true, then my Host ID (and the settings we put under it in the registry) seem to be related to the IDE and where it stores and retrieves it's file and information and has nothing to do with my HostItems or HostObjects.  In fact it doesn't really even seem to have any real connection to my Host Application other then the fact that when I want to open an IDE/DTE I need to tell it which HostID Entry to look under for behavioral info.

    Correct- the VSTA registries are basically for the IDE and creating/opening project templates.  They have nothing to do with HostItems, HostObjects, or the Host Application.

     

    The ShapeApp DPM sample uses a registry to hold the location of the Drawing.cs file.  The registry they use for this is an application registry- it is not in or related to the VSTA registry hives.  IMO it would have been clearer to use a known location instead of a registry value (the location of the file is written to the registry in the setup file).  The Drawing.cs can be thought of as an “Item Template” just like other Item Templates in Visual Studio.  Item Templates are added to a project, which is based off a Project Template.

     

     


    3) Ok, so when I'm creating a DTE the first parameter I pass to the ProviderGetDTE() method is just the HostID that will be used to get the behaviroal information mentioned in #2 and doesn't imply any particular HostItem or Object Model.  In fact, not until I load a project using Solution.AddFromTemplate() do I actually start to imply the use of any particular HostItem... and that's only because I'm loading from a template that has a default HostItem specified.

    > Ok, so when I'm creating a DTE the first parameter I pass to the ProviderGetDTE() method is just the HostID that will be used to get the behaviroal information mentioned in #2 and doesn't imply any particular HostItem or Object Model.

    Correct- ProviderGetDTE only deals with the DTE- it has nothing to do with what templates or projects are loaded and nothing to do with DPM. 

    > In fact, not until I load a project using Solution.AddFromTemplate() do I actually start to imply the use of any particular HostItem... and that's only because I'm loading from a template that has a default HostItem specified.

    No-  Solution.AddFromTemplate loads a template which has an Entry Point.  The Entry Point in the template will not be a Host Item, it will contain 0 or more HostItems and the HostItems are programmatically added to the “Host” (Entry Point of the template, my term).  Solution.AddFromTemplate is used to load a project based on a template- it doesn’t matter whether or not the project from this will be used in a DPM context.

     


    4) So, each project template has one entry point, but once I load the project template in the IDE I can add other HostItems to the template, in addition to the one that already is in the project template.  And, this one that's in the template must have an entry point.  My confusion is around your statement about app and doc having to use different templates (which would end up being different AddIns/Dlls) because they both need their own entry point.  Couldn't I have one project template with the app HostItem specified as the entry point and then add multiple doc HostItems at run-time to achieve the same affect?

    > So, each project template has one entry point

    Yes. 

    > once I load the project template in the IDE I can add other HostItems to the template, in addition to the one that already is in the project template.

    Project Templates do not contain HostItems- they must be added programmatically (although you can include the file in the template that will be the code representation of the HostItem

    > My confusion is around your statement about app and doc having to use different templates (which would end up being different AddIns/Dlls) because they both need their own entry point. 

    Because each template can only contain one entry point Application level add-ins and Document level add-ins each have their own template with the corresponding entry point.

    > Couldn't I have one project template with the app HostItem specified as the entry point and then add multiple doc HostItems at run-time to achieve the same affect?

    You could have a project based off an application level template.  This project would have an application level Entry Point, and that Entry Point would serve as the “Host” for document HostItems.  This would achieve the same effect through DPM.

    This is not the same as having an Application level template with Document entry points in it- templates and projects based off them have only one entry point.  Note:  it is possible to manually edit a template to use both Application and Document level Entry Points; however, that is more advanced than a typical DPM scenario- If you are interested in that, master DPM first.

     

    >Also I'm reading this from the SDK doco, which is using plurals to suggest that you can have multiple entry points in a project:

    >"Host items in add-in projects derive from entry point classes in the proxy assembly. An entry point is a proxy type that provides direct access to an object in the object model of the host application. The entry point type is instantiated when the host application loads an add-in. Typically, the entry point is a proxy for a host type at the top of the object model hierarchy, such as an Application class."

    This applies to DPM projects- this is misleading when said in the context of nonDPM add-ins which have only one entry point.

    >Maybe this is all simpler than I'm making it out to me.  Is it just that when an AddIn loads, any HostItem Classes in it with an Entry Point will be instantiated and fire their Startup events?  Then if I programmatically add some later in the same session, they won't get instantiated until the addin is re-loaded?

    > Is it just that when an AddIn loads, any HostItem Classes in it with an Entry Point will be instantiated and fire their Startup events? 

    Sort of- DPM add-ins (multiple entry points) are loaded differently than nonDPM add-ins

    DPM style load:

    // Initialize AddIn by calling into functions of the AddIn EntryPoint instance.

    // Because for Document AddIn, Document and each drawing are all EntryPoint, We need to use IMultipleEntryPoint.

    IMultipleEntryPoint multipleEntryPoint = addIn as IMultipleEntryPoint; //DPM

    multipleEntryPoint.Initialize(addInToken[0].AssemblyName.FullName, entrypointNameList, this.serviceProvider); //DPM

     

    NonDPM style load:

    // Initialize AddIn by calling into functions of the AddIn EntryPoint instance.

    addIn.Initialize(this.serviceProvider);

    >Then if I programmatically add some later in the same session, they won't get instantiated until the addin is re-loaded?

    Correct.

     


    5) I know this is new, but it seems important to the other points.  When I use ProjectGen, it requires me to pick a HostITem that will be the "Base Type" so it seems that Project Templates must have a HostItem in them in order to load them up.  This does't make sense because I thought an AddIn didn't have to have an particular HostItem in them.  Is this just becuase it's a template and it's not too valuable as a template without at least one HostItem clas?

    The BaseType is the Entry Point that will act as the “Host” to the “HostItems”.  Here the choice in terminology is VERY unfortunate since you are asked to pick a “Base type” and a “Host item name”.  This “Host item name” is not referring to the DPM HostItem- it is actually referring to the start up class and PrimaryCookie (in the designer file) of the add-in.



  • 04-20-2008 6:10 PM In reply to

    • Terry
    • Top 10 Contributor
    • Joined on 05-10-2006
    • Posts 90

    Re: Finally an easy one

    Thanks for continuing the conversation around these concepts.  The reason I'm so concerned about coming to a full understanding of the possibilities is because of our intended use of VSTA will likely include hundreds of AddIns across several different run-time applications, hundreds of HostItems, thousands of HostObjects.  What's more, our addin's will be versioned by time-stamp and we will be loading multiple versions and running them in parallel.  It is also our goal to integrate VSTA in the Business Logic layer, which will be used by multiple applications (.exe's)so the concept of a Host Application Template with a Application Entry point might not have any context in our architecture.  I guess what I'm saying is that the Drawing app is fundamentally different than what we are trying to do and it's very difficult to draw (not pun intended) any parallels between them.

    In any case, I think the major stumbling block is the DMP/non-DMP concept.  It seems that most of these core concepts revolve around an understanding of the differences.

    What is the real difference between DMP and non-DMP?  I thought it was just whether or not you added Host Items and Host Objects at run-time, but from your posts it would seem that there are tangible differences between them.  You mention using a different method for loading addin's and also how the project templates might be different.  The thing the scares me most is that I have a working implementation and I don't know if it's DPM or not because I don't know how the code would be different.

     

  • 04-21-2008 10:05 AM In reply to

    • Melody
    • Top 10 Contributor
    • Joined on 04-26-2007
    • Syracuse, NY
    • Posts 248

    Re: Finally an easy one

    Terry,
    >What is the real difference between DMP and non-DMP
    DPM builds on VSTA- I am drawing attention to the differences, and using the "nonDPM" term, because there seems to be a lot of confusion about VSTA.  Understanding VSTA is a perquisite to understanding DPM and it is easier to first understand VSTA without DPM than to try tackling VSTA with DPM.  Also, i

    DPM is just a certain way of doing VSTA.


    >I thought it was just whether or not you added Host Items and Host Objects at run-time
    DPM allows you to name host items and host objects and program against them using "me" or Object1.  With a "nonDPM" add-in you could still add the same types (as the host item or host object) and program against them, but would have to identify the host item or host object as a specific member of a collection.  

    For example:
    DPM
    Me.obj1, Me.obj2, Me.obj3

    nonDPM
    Me.obj(1), Me.obj(2), Me.obj(3)


    To add a shape to a drawing that already has a circle using a document level add-in:
    DPM (from Drawing1.cs)
    Me.Shapes.Add(Me.Circle1.Clone())

    nonDPM (document level)
    Me
    .Drawings(1).Shapes.Add(Me.Drawings(1).Shapes(1).Clone())


    nonDPM (application level)
    Me
    .Document.Drawings(1).Shapes.Add(Me.Document.Drawings(1).Shapes(1).Clone())

    Everything you can do programmatically with a DPM add-in you can do with a nonDPM  add-in.  The difference is in how objects are identified.



    >The thing the scares me most is that I have a working implementation and I don't know if it's DPM or not because I don't know how the code would be different.
    The SDK includes several samples- basic, macro recording, and DPM.    You should start with the basic sample and perform the walkthroughs.  If you are more comfortable with VB.net, we have a ShapeAppBasicVB sample.

    Overall, I think you should look at the basic sample and do the walkthroughs.  You should not be considering DPM until you have been through the basic sample and walkthrough.  If you are still having trouble getting the ShapeAppBasic sample to work, please let me know.

    Hopes this helps,
    -Melody
  • 04-22-2008 12:41 AM In reply to

    • Terry
    • Top 10 Contributor
    • Joined on 05-10-2006
    • Posts 90

    Re: Finally an easy one

    After a lot of jacking around I was able to get the VB ShapeAppBasic to work, though it's really not doing anything that I can see (after stepping through all the VSTA-related code) that suggests to me that it's nonDPM. 

    I created an addin project and put some code in.  Then ran the app in debug mode to find that it seems to be doing 2 of the same steps that I'm doing in my DMP solution:

    1) Builds a Service Container (including a host item provider and a host item type provider).  The Service Container and the providers appear to function the same no matter what example code I look at, which make sense because their function (prupose) is relatively straightforward.  One gets Host Items and Objects for the Addin and the other translates types

    2) Loads AddIns by simply taking a known location on Disk and searching any directories for .dll files and try to load them.  Of course in this case, it only finds one (my addin) and this one has just the following code in it:

    Private Sub AppAddin_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup

       Me.Drawings.Add(Me.NewDrawing())

    End Sub

    This, of course gives me a new, blank drawing as soon as the app loads.

    As you pointed out, I have to use Me.Drawings(0) to get at the new drawing I just created.  But, to me this is because the class we chose as an entry point (Application) had that collection available.  Is everything up to this point what makes this sample nonDPM, or "normal VSTA"?

    We could have easily hidden that documents property and manually added a Host Object to the Application "HostItem" (incorrect term since this is nonDPM?) when the drawing was created, and that would have allowed the Me.Drawing1 syntax to do the same thing.

    So, if I open this "standard VSTA" project, Add a VSTADesignTimeClass with the normal functionality and write code to load the IDE from the UI the developer would see basically the same thing they do now.  Then I could write some code like this:

       hstHostItem = HostAdapter.ProjectHostItems(HostItemCookie).ProgrammingModelHostItem

       hstHostItem.HostObjects.Add("Drawing1", "ShapeAppVB.Drawing", strHostObjectCookie)

    Then I should be able to go into the IDE and use Me.Drawing1.  I would of course need to add code to my GetHostObject in the HostItemProvider to round up this Drawing, but that's no big deal either.

    Does adding this functionality to the base sample magically turn it into "DMP"?  I sure hope there's more to it than this...

     

     

  • 04-22-2008 12:30 PM In reply to

    • Melody
    • Top 10 Contributor
    • Joined on 04-26-2007
    • Syracuse, NY
    • Posts 248

    Re: Finally an easy one

    Terry, 

    I’m glad you were able to get the basic sample working and loading add-ins.  The VB samples available on line are based on the VSTA v 1 SDK sample OM which did not include a document class.

    >1) Builds a Service Container (including a host item provider and a host item type provider).  The Service Container and the providers appear to function the same no matter what example code I look at, which make sense because their function (prupose) is relatively straightforward.  One gets Host Items and Objects for the Addin and the other translates types

    The service container and Host Type Map Provider (HTMP) function the same way in all of the SDK samples.  The Host Item Provider (HIP) functions differently in the DPM sample- it is able to pass the add-in the requested instance of the application, document, drawing, or shape type where as the basic sample only passes an instance of the application.  The DPM HIP also uses cookies to identify specific HostItems (drawings) and HostObjects (shapes)- this is a unique concept to DPM

     

    >2) Loads AddIns by simply taking a known location on Disk and searching any directories for .dll files and try to load them.  Of course in this case, it only finds one (my addin) and this one has just the following code in it:

    For the basic (and advanced/macro recording) sample, all application level add-ins in the known location are loaded using a single entry point.  For the DPM sample one add-in associated with the current document is loaded using multiple entry points.

     

    > As you pointed out, I have to use Me.Drawings(0) to get at the new drawing I just created.  But, to me this is because the class we chose as an entry point (Application) had that collection available.  Is everything up to this point what makes this sample nonDPM, or "normal VSTA"?

    With nonDPM VSTA all objects must be identified like “Me.Obj(1)”, not “Me.Obj1”.  For the add-in you made you would have to specify a shape like “Me.Drawing(1).Shape(1)”.  This is the nonDPM way.

    > We could have easily hidden that documents property and manually added a Host Object to the Application "HostItem" (incorrect term since this is nonDPM?) when the drawing was created, and that would have allowed the Me.Drawing1 syntax to do the same thing.

    HostItem and HostObject should not be used in the nonDPM context.  If you hid code that allowed you to use Me.Drawing1 in this add-in, it would still not be DPM because of the host/add-in relationship.  The basic sample cannot load add-ins (even DPM add-ins) in a DPM way for two reasons- the HIP and the way add-ins are loaded and discovered.   If you change these, then the add-in could be loaded but the host would still not offer DPM functionality.

    > Add a VSTADesignTimeClass with the normal functionality

    I’m not sure if you are referring to “normal” as DPM or nonDPM.  In the DPM example the VSTADesignTimeClass is designed for DPM.  In the Advanced or MacroRecording samples the VSTADesignTimeClass is designed for macro recording (nonDPM).  In the DPM design time class methods are included to assign cookies and track changes in HostItems and HostObjects.  These methods include AddDrawingProjectHostItem, AddEntryPointToDocument, and drawing_[NameChanged, Inserted, Remvoed, ShapeAdded, ShapeRemoved].   These methods to handle HostItems and HostObjects are essential to DPM and not found in nonDPM implementations. 

     

    > Does adding this functionality to the base sample magically turn it into "DMP"?  I sure hope there's more to it than this...

    To change the basic sample to a DPM implementation,

    1)      1)  Modify the HIP

    2)      2)  Add the ability to load DPM add-ins

    3)      3)  Add a DPM implementation of the design time class

     

    I’ve posted a modified sample: ShapeApp_BasicAdvDPM_CSharp that may help clear up these differences.  Note that the HIP is the DPM HIP- that is because the DPM HIP includes the functionality needed for nonDPM implementations (the ability to pass the application object). 

    In this sample, I started with the DPM sample and added basic functionality (the ability to discover and load application level add-ins) and incorporated the IDE in a nonDPM way.  To use this sample, extract it to C:\ShapeAppSamples, run the setup file, build the sample add-in included and run the sample.  The sample will load the sample add-in built above.  Then launch the nonDPM and DPM IDE’s.

  • 04-22-2008 9:06 PM In reply to

    • Terry
    • Top 10 Contributor
    • Joined on 05-10-2006
    • Posts 90

    Re: Finally an easy one

    "The service container and Host Type Map Provider (HTMP) function the same way in all of the SDK samples.  The Host Item Provider (HIP) functions differently in the DPM sample- it is able to pass the add-in the requested instance of the application, document, drawing, or shape type where as the basic sample only passes an instance of the application.  The DPM HIP also uses cookies to identify specific HostItems (drawings) and HostObjects (shapes)- this is a unique concept to DPM"

    Isn't the code in the GetHostObject function the only difference?  And at that, it's just the fact that it has a select case that checks for different types and returns the correct object based on the cookie?  If so, this seems like a very subtle difference between DPM and nonDPM.

    This next section is really the crux of what I'm after:

    "To change the basic sample to a DPM implementation,

    1)      1)  Modify the HIP

    2)      2)  Add the ability to load DPM add-ins

    3)      3)  Add a DPM implementation of the design time class"

    1) 1) My understanding of modifying the HostItemProvider to support DPM is just adding code to return additional objects based on what cookie and type was requested.

    2) 2) This one is new information for me.  What do you do in order to load a DPM Add-in?  How is the code different than the code in the VB sample you provided the link to?

    3) 3) This is what I was refering to by adding the DesignTime class, and of course adding code that will add HostItems to an open DTE project, or add objects to a Given HostItem.  This I understand how to do now.

    So, in the three things you mentioned that are necessary to turn nonDPM into DPM I believe I understand two of them.  It's the #2 item above that must be the key to the real difference in code.  What I mean is that #1 and #2 are additional code added to a nonDPM i my mind.  #2 sounds like it might be replacing some nonDMP code with different method calls or parameters in order to support DPM.

     

  • 04-23-2008 9:50 AM In reply to

    • Melody
    • Top 10 Contributor
    • Joined on 04-26-2007
    • Syracuse, NY
    • Posts 248

    Re: Finally an easy one

    Terry,
    >Isn't the code in the GetHostObject function the only difference?  And at that, it's just the fact that it has a select case that checks for different types and returns the correct object based on the cookie?
    Correct- to make a "nonDPM" HIP a DPM HIP you change the GetHostObject function to return specific instances of a variety of types based on cookies.  That is the only change to the HIP.

    >2) This one is new information for me.  What do you do in order to load a DPM Add-in?  How is the code different than the code in the VB sample you provided the link to?

    DPM add-ins (multiple entry points) are loaded differently than nonDPM add-ins
    DPM style load:
    // Initialize AddIn by calling into functions of the AddIn EntryPoint instance.
    // Because for Document AddIn, Document and each drawing are all EntryPoint, We need to use IMultipleEntryPoint.

    IMultipleEntryPoint