How do I expose my COM host object to the VSTA add-in?

158 views Asked by At

Does anybody upgraded VSTA 2.0 Add-in development to VSTA 2012? if Yes,

Could you please help me on this subject "How do I expose my COM host object to the VSTA add-in?"

i am working with VSTA 2012, The sample application which comes with VSTA 2012 "MyVSTAHost" doesn't cover exposing host object to vsta add-in.

where as in vsta 2.0 shapeappadvancedmfc covers this, but i no longer able to use hostitemprovider and contract concept in vsta 2012 as it is no longer supported in vsta 2012.

note: In VSTA 2.0 i am able to invoke my host application dispinterface methods with the add-in but do know how to do it in VSTA 2012, i dont see the support of poxygen in VSTA 2012 and some of the runtime namespaces are no longer supported in VSTA 2012.

Thanks and regards,

Nayaz

1

There are 1 answers

0
Paul Sweatte On

Use the Visual Studio Package Template:

Unmanaged VSPackages (including those generated by the Visual Studio Package Template) use ATL-style .rgs files to store registration information. The .rgs file format is specific to ATL and cannot generally be consumed as-is by an installation authoring tool. Registration information for the VSPackage installer must be maintained separately. For example, developers can keep files in .reg format in sync with .rgs file changes. The .reg files can be merged with RegEdit for development work or consumed by an installer.

Sometimes, a COM interface generates an IUnknown object, and the COM interface then passes it as type void **. These interfaces are especially important because if the variable is defined as [out] in the IDL, then the IUnknown object is reference-counted with the AddRef method. A memory leak occurs if the object is not handled correctly.

An IUnknown object created by the COM interface and returned in an [out] variable causes a memory leak if it is not explicitly released.

Managed methods that handle such objects should treat IntPtr as a pointer to an IUnknown object, and call the GetObjectForIUnknown method to obtain the object. The caller should then cast the return value to whatever type is appropriate. When the object is no longer needed, call Release to release it.

In Visual Studio 2015 they are gone (no “Tools” > “Add-In Manager” menu). So, you have to migrate your add-in to a package, which can be quite a daunting task depending on the size and complexity of your add-in (only alleviated by the fact that you can still use the automation model (EnvDTE) from a package.

References