Am I supposed to use the New() sub in an Automation addin?

Jan 19, 2013 at 9:29 PM

I've seen that the NetOffice Project Wizard in VB 2010 Express generates a Public Sub New() subroutine as part of the autogenerated code. My question is, am I supposed to have code in it? I've tried putting some dummy code but it stops PowerPoint from properly loading the addin.

Thanks in advance.

Developer
Jan 20, 2013 at 11:52 AM
Edited Jan 20, 2013 at 11:53 AM

Of course you may write some initialization code in the constructor (i.e. New() Sub). For example I have the following New Sub:

Public Sub New()
      togglePressed = False
End Sub

... and it doesn't prevent my PowerPoint addin from loading. Just a non-empty New Sub can't be a problem. May be you constructor code make something sensitive to addin loading (memory issue, unmanaged resource trick, COM object, etc.). What does you dummy code look like?

Coordinator
Jan 20, 2013 at 3:32 PM

be careful with ctor code because the method is called as first in your addin. the next called method is the OnConnection procedure from the IExtensibility2 Interface.
your host application instance is set here into a local variable. NOW you can use the automation object model from powerpoint in your addin. in other words: use the ctor for own stuff but dont access power point here. very comon is to use OnConnection instead of the ctor.