Integrating Delphi COM

 

Gary did some work using Delphi COM a few years back -- he integrated VBA into a Delphi application. 

Here's an example of the tiny managed proxy,  called ObjectModelAgent.

-Host app calls SetOM with IDispatch* or IUnknown* parameter.

-Addin calls GetOM

-Proxy layer code for GetOM marshals the COM ptr to a managed Object 

Here's example for the Addin source:

==

<System.AddIn.AddIn("AppAddIn", Version:="1.0", Publisher:="", Description:="")> _
Partial Class MacroAddIn

    Public Sub Macro1()
 
    End Sub

#Region "Startup Code"
    Dim Application As Interop.Assembly.Application

    Private Sub MacroAddIn_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup
        Me.Application = CType(Me.GetOM(), Interop.Assembly.Application)

    End Sub

    Private Sub MacroAddIn_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown

    End Sub
#End Region


End Class
==

To use this example:

-The host would be able to call managed code method SetOM().

-The COM object Model would be fed to tlbimp to create an interop assembly.

- and the VSTA addin project would set a reference to the interop assembly

Another approach is to make a similar tiny unmanaged proxy using COM typelibrary to pass the object model instead of the managed ObjectModelAgent exanple attached.

The host application would do something like this:

#region VSTA Integration Code

private Interop.Assembly.Application m_Application;

omAgent = new ObjectModelAgent.ObjectModelAgent();

omAgent.SetOM(m_Application);

//pass OMAgent as host object to hook up with VSTA addin entry point

InitializeVSTA(omAgent, MainFrameHWND);

LoadMacros(); // when macro addin loads, the add-in: calls proxy of ObjectModelAgent.GetOM", gets instance of m_application, casts it to Interop.Assembly.Application, this allows it to call directly into host COM OM

#endregion // VSTA Integration Code

 

 

 


Posted May 26 2009, 01:19 PM by BillL
Filed under: , , ,
Copyright Summit Software Company, 2008. All rights reserved.