AddAdvise - The SDK Fails

Started by bobsupercow, February 24, 2011, 12:15:41 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

bobsupercow

I recently ran into an issue converting my VSTO addin from WithEvents to the recommended EventSink driven format. AddAdvise always threw an HRESULT Exception at runtime. After much weeping, knashing of teeth and googling, I came across this answer provided by David Parker:

http://www.eggheadcafe.com/software/aspnet/30017966/vsto-addadvise-problem.aspx
Quote
I think you need to add the <ComVisible(True)> _ before Public Class
EventSink:

Public Class EventSink
David

So the following code stopped my problems:
<System.Runtime.InteropServices.ComVisible(True)> Public Class EventSink
    Implements Microsoft.Office.Interop.Visio.IVisEventProc


However, I don't fully understand what's going on, since my Class Properties ComVisible is set = True at design time in Visual Studio. Does it randomly change to False at some point. I guess I just want clarification on why this line of code is required seeing as it is already set = True.


The SDK provides no guidance on this. In fact, as another issue altogether it's definition of the VisEventProc Function is innaccurate.

From 12.0 Reference Library and what actually compiles.
   
QuotePrivate Function VisEventProc( _
        ByVal eventCode As Short, _
        ByVal source As Object, _
        ByVal eventId As Integer, _
        ByVal eventSequenceNumber As Integer, _
        ByVal subject As Object, _
        ByVal moreInformation As Object) As Object _
        Implements Microsoft.Office.Interop.Visio.IVisEventProc.VisEventProc

From 12.0 SDK and what does not compile.

QuotePrivate Function IVisEventProc_VisEventProc( _
    ByVal nEventCode As Integer_
    ByVal pSourceObj As Object, _
    ByVal nEventID As Long, _
    ByVal nEventSeqNum As Long, _
    ByVal pSubjectObj As Object, _
    ByVal vMoreInfo As Variant) As Variant   _
   Implements Microsoft.Office.Interop.Visio.IVisEventProc.VisEventProc
End Function

This also led to tons of issues reusing existing code.

Lesson learned: The SDK is a reference, but it can be wrong. Don't rule that out as an option when trying to track down bugs.