Unclear error message when trying to catch the MouseUp event

J

Josef Meile

Hi,

I'm trying to catch the MouseUp event from a C# visio addon like this:

const short visEvtAdd = -32768;
Visio.EventList eventsDocument;

try
{
eventsDocument = VisioDocument.EventList;
eventsDocument.AddAdvise(
(short)Visio.VisEventCodes.visEvtCodeMouseUp,
CExeAddon.EventHandler, "", "");
}
catch (Exception err)
{
System.Diagnostics.Debug.WriteLine(err.Message);
}

But I got an unclear error that says me nothing:

Message: An exception occurred.
Exception Type:System.Runtime.InteropServices.COMException

StackTrace:
at Microsoft.Office.Interop.Visio.EventListClass.AddAdvise(Int16
EventCode, Object SinkIUnkOrIDisp, String IIDSink, String TargetArgs)
at EVA.CApplication.AssociateEvents() in c:\\addon\\capplication.cs:line
152"

I catched other events successfully by changing the event codes and it had
worked. Only the MouseUp event gives me problems.

Ah, if you are wondering how my EventSink class looks like, it is the same
one included with the SDK examples.

Does anybody know what the problem could be?

Regards,
Josef
 
J

Josef Meile

Ok, I solved it.

I saw there is also an example to handle the mouse events. It seems that one
have to define a separate event handler to catch mouse events. Sorry if I
botther you, but this is not mentioned in the help page of the MouseUp event.
On the contrary, this paragraph from the help is contradictory:

"""
If you want to create your own Event objects, use the Add or AddAdvise
method. To create an Event object that runs an add-on, use the Add method as
it applies to the EventList collection. To create an Event object that
receives notification, use the AddAdvise method. To find an event code for
the event you want to create, see Event codes.
"""

I think somewhere it should mentioned that you can't use addAdvise with the
Mouse events. In this case you have to create a handler of the type
Visio.EWindow_MouseUpEventHandler. I will submit a comment in the online help
page in msdn.

Thanks,
Josef
 
J

Josef Meile

I have to add something more to my previous message:

The EventSink class of the Code Librarian has a case for the
visEvtCodeMouseUp event. The example should be updated as well because if you
add:

eventsDocument.AddAdvise((short)Visio.VisEventCodes.visEvtCodeMouseUp,
EventHandler, "", "");

you will get the exception I mentioned before. I tested it with a Windows
application referencing the Visio type library 11.0 and containing only the
EventSink class of the Visio SDK.

Regards,
Josef Meile
 

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