Version neutral PIA's - of a more up to date variety

Add-in Express™ Support Service
That's what is more important than anything else

Version neutral PIA's - of a more up to date variety
 
Bargholz Thomas




Posts: 242
Joined: 2006-12-18
Hi,
I have an add-in which works for Office 2003 and 2007. And when Office 2010 is released, that needs to be supported too. So I'm using the version neutral PIA's and that works perfectly for all the common and generic stuff.
However, my customers expect that new features of newer Office applications are supported, and that leaves me with a problem, because the PIA's doen't contain this information. This can to great extend be handled by reflection, but more and more often do I run into stuff I simply can get to work at the level I and my customers expect. If I had up-to-date (or version specific) PIA's, that wouldn't be a problem. But having version specific builds of my add-in is not a solution that is easily handled and maintained.

So my question is:
Would it be possible for you to supply an updated set of version neutral Office PIA's, which covers Office 2003 and on?
Or is it possible for me to generate these my self? And if so, how?

Regards
Thomas
Posted 03 Feb, 2010 04:38:49 Top
Andrei Smolin


Add-in Express team


Posts: 18844
Joined: 2006-05-11
Hi Thomas,

Version-neutral interops provide early-binding information for the oldest version of an Office application. Because the backward-compatibility is still respected by Microsoft developers, this allows your add-in to use the same COM interface or its members in all Office versions starting from Office 2000.

In your situation, the best way is to use interops for Office 2003. In this case, your add-in project will use early-binding information on all COM interfaces and their members available in Office 2003 (i.e. interfaces available in Office 2000 plus interfaces and members introduced in Office 2002 and 2003). Because of the backward compatibility, your add-in will work in Office 2007 and higher.

To access features introduced in Office 2007 and 2010 in your add-in based on Office 2003 interops, you need to use late binding; please search our forums for InvokeMember.

Finally, there's no way to have an interop that covers several versions of the same Office application.

If you have more questions on this, please do ask them - I'm working on the manual and I'm interested in that sort of questions.


Andrei Smolin
Add-in Express Team Leader
Posted 03 Feb, 2010 12:19:03 Top
Bargholz Thomas




Posts: 242
Joined: 2006-12-18
Hi Andrei,
So I can simply just switch the current PIAs that came as the version neutral PIA's with Add-in-express, with Office 2003 PIA*s, and all should be well?
Regards
Thomas
Posted 03 Feb, 2010 15:04:19 Top
Martin Kirsten




Posts: 71
Joined: 2008-04-23
Hi Andrei

I have exactly the same issue. I am porting our Office 2007 Add-in to Office 2003, and am trying a "Version Neutral PIA" solution. This works fine except that I can't use any of the Office 2007-specific items (such as the new file types).

Also, could you please provide an example of using late binding?

Thanks!

Martin
Posted 04 Feb, 2010 02:39:42 Top
Tobias B?hm




Posts: 73
Joined: 2009-07-06
Also, could you please provide an example of using late binding?


Martin, maybe that (http://www.add-in-express.com/forum/read.php?FID=5&TID=6626&MID=33122) thread helps you.

Regards,
Tobias
Posted 04 Feb, 2010 03:23:39 Top
Martin Kirsten




Posts: 71
Joined: 2008-04-23
OK so I have used Office 2003 PIAs instead of the Version Neutral PIAs. All working good so far in both Office 2003 and 2007!

(Thanks for the link, Tobias!)
Posted 04 Feb, 2010 07:35:01 Top
Andrei Smolin


Add-in Express team


Posts: 18844
Joined: 2006-05-11
I have the following sample: an add-in calling public members of another add-in via late binding.

The "Server" add-in (MyAddin356)
=================
    Private _value As String = ""
    Private Const notSet As String = "not set"

    Public Property MyProperty() As String
        Get
            If String.IsNullOrEmpty(_value) Then
                Return notSet
            Else
                Return _value
            End If
        End Get
        Set(ByVal value As String)
            System.Windows.Forms.MessageBox.Show("MyProperty Set has been called", "MyAddin356")
            _value = value
        End Set
    End Property

    Public Sub MySub()
        System.Windows.Forms.MessageBox.Show("MySub has been called", "MyAddin356")
    End Sub

    Public Sub MySubWithParameter(ByVal aParameter As String)
        _value = aParameter
        System.Windows.Forms.MessageBox.Show("MySub2 has been called; _value is '" + _value + "'", "MyAddin356")
    End Sub

    Public Function MyFunction(ByVal aParameter As String) As String
        _value = aParameter
        Return _value
    End Function


The "Client" add-in (MyAddin357)
===============
    Private myOtherAddin As String = "MyAddin356.AddinModule"

    Private Function GetAddinObject(ByVal progID As String) As Object
        Dim Addin As Office.COMAddIn = OutlookApp.COMAddIns.Item(progID)
        If Addin IsNot Nothing Then
            Dim AddinObj As Object = Addin.Object
            If Addin.Connect Then
                Return AddinObj
            End If
        End If
        Return Nothing
    End Function

    Private Sub btnPropertyGet_Click(ByVal sender As System.Object) Handles btnPropertyGet.Click
        Dim AddinObj As Object = GetAddinObject(myOtherAddin)
        If AddinObj IsNot Nothing Then
            Try
                Dim returnValue As Object = _
                    AddinObj.GetType().InvokeMember("MyProperty", Reflection.BindingFlags.GetProperty, Nothing, AddinObj, Nothing)
                System.Windows.Forms.MessageBox.Show("MyProperty returned " + returnValue.ToString(), "MyAddin357")
            Catch ex As Exception
                System.Windows.Forms.MessageBox.Show("btnPropertyGet_Click. Error:" + ex.Message, "MyAddin357")
            End Try
        End If
    End Sub

    Private Sub btnPropertySet_Click(ByVal sender As System.Object) Handles btnPropertySet.Click
        Dim AddinObj As Object = GetAddinObject(myOtherAddin)
        If AddinObj IsNot Nothing Then
            Try
                Dim parameter As String = AdxCommandBarEdit1.Text
                AddinObj.GetType().InvokeMember("MyProperty", BindingFlags.SetProperty, Nothing, AddinObj, New Object() {parameter})
            Catch ex As Exception
                System.Windows.Forms.MessageBox.Show("btnPropertySet_Click. Error:" + ex.Message, "MyAddin357")
            End Try
        End If
    End Sub

    Private Sub btnCallSub_Click(ByVal sender As System.Object) Handles btnCallSub.Click
        Dim AddinObj As Object = GetAddinObject(myOtherAddin)
        If AddinObj IsNot Nothing Then
            Try
                AddinObj.GetType().InvokeMember("MySub", Reflection.BindingFlags.InvokeMethod, Nothing, AddinObj, Nothing)
            Catch ex As Exception
                System.Windows.Forms.MessageBox.Show("btnCallSub_Click. Error:" + ex.Message, "MyAddin357")
            End Try
        End If
    End Sub

    Private Sub btnCallSubWithParameter_Click(ByVal sender As System.Object) Handles btnCallSubWithParameter.Click
        Dim AddinObj As Object = GetAddinObject(myOtherAddin)
        If AddinObj IsNot Nothing Then
            Try
                Dim parameter As String = AdxCommandBarEdit1.Text
                AddinObj.GetType().InvokeMember("MySubWithParameter", Reflection.BindingFlags.InvokeMethod, Nothing, AddinObj, New Object() {parameter})
            Catch ex As Exception
                System.Windows.Forms.MessageBox.Show("btnCallSubWithParameter_Click. Error:" + ex.Message, "MyAddin357")
            End Try
        End If
    End Sub

    Private Sub btnCallFunction_Click(ByVal sender As System.Object) Handles btnCallFunction.Click
        Dim AddinObj As Object = GetAddinObject(myOtherAddin)
        If AddinObj IsNot Nothing Then
            Try
                Dim parameter As String = AdxCommandBarEdit1.Text
                Dim returnValue As Object = _
                    AddinObj.GetType().InvokeMember("MyFunction", Reflection.BindingFlags.InvokeMethod, Nothing, AddinObj, New Object() {parameter})
                System.Windows.Forms.MessageBox.Show("MyFunction returned " + returnValue.ToString(), "MyAddin357")
            Catch ex As Exception
                System.Windows.Forms.MessageBox.Show("btnCallFunction_Click. Error:" + ex.Message, "MyAddin357")
            End Try
        End If
    End Sub


Note that CommandBar edit box will save the value you entered ONLY if you press {Enter} or if you move the focus off the control. I've run into that pecularity (it wasn't for the first time) when testing those samples.


Andrei Smolin
Add-in Express Team Leader
Posted 05 Feb, 2010 12:52:46 Top