VSTO AddAdvise Problem

J

John

Hi there,

I'm slowly learning about the AddAdvise event handling process and trying to
include it in a VSTO SE add-in. I'm getting an error on the AddAdvise line
(near the bottom of the code). I'm using the EventSink class from the 2007
SDK sample and have tried to adapt the "AddAdviseDemo" and a bit of the
Flowchart sample.

In debug it runs through fairly happily, instantiates the sink class
(applicationEventSink) and establishes an application EventList reference,
until it gets to the AddAdvise method itself.

Can anyone help shed some light? I'm begining to count in days now!

Thanks

John


Imports Visio = Microsoft.Office.Interop.Visio

Imports System.Runtime.InteropServices

public class ThisAddIn

Private visioApplication As Visio.Application

Private resultEvent As Visio.Event

Private applicationEventSink As Visio.IVisEventProc



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

'DemoAddAdvise(Globals.ThisAddIn.Application)

HookupAppEvents()

End Sub



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

UnHookAppEvents()

End Sub



Private Sub HookupAppEvents()

Dim applicationEventList As Visio.EventList

Dim validVisioVersion As Boolean = True

Dim majorVersion As Int16 = 0

Try

If (visioApplication Is Nothing) Then

visioApplication = CType(Globals.ThisAddIn.Application, _

Visio.Application)

' Make sure that we're running against the correct version of Visio.

majorVersion = CType _

(Convert.ToDouble(visioApplication.Version, _

System.Globalization.CultureInfo.InvariantCulture), Short)

If (0 = majorVersion Or _

majorVersion < MinVisioVersion) Then

DisplayException(visioApplication.AlertResponse, _

LoadString("ErrorVisioVersion"))

validVisioVersion = False

End If

If validVisioVersion Then

applicationEventSink = New EventSink

' Listen to the marker events.

applicationEventList = visioApplication.EventList

'****ERRORS ON NEXT LINE (2032465768 "An exception occured")*****



resultEvent = applicationEventList.AddAdvise( _

CShort(Visio.VisEventCodes.visEvtApp + _

Visio.VisEventCodes.visEvtMarker), _

applicationEventSink, "", "")

End If

End If

Catch err As COMException

MsgBox(err.ErrorCode & " - " & err.Message, MsgBoxStyle.OkOnly, "Error")

'DisplayException(visioApplication.AlertResponse, err.Message)

End Try

End Sub

End class
 
D

David Parker

John,

I think you need to add the <ComVisible(True)> _ before Public Class
EventSink:

<ComVisible(True)> _
Public Class EventSink


David
 
J

John

Perfect David. Worked a treat.

I can now spend the rest of the weekend getting the rest going.

Thanks again.

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top