Hi, Scott: I've gotten more feedback from several members of the team on
this. Here's our recommendation (this is related to your other post that
I'll be responding to as well):
How did you import that Visio type library? We recommend using #import if
you are using Visual Studio. We do not recommending using MFC's import
mechanism. The wrapper objects created by MFC import mechanism are late
bound and hence slower. MFC generator also doesn't work well with safe
arrays and Visio has a number of methods that use safe arrays. For more info
on the limitation of the MFC generator, see these links
http://support.microsoft.com/default.aspx?scid=kb;en-us;158451
http://support.microsoft.com/default.aspx?scid=kb;en-us;237554
The IVisEventProc interface is defined in Visio's type library because it
defines a communication protocol with Visio BUT Visio doesn't implement it.
Clients of Visio who use AddAdvise must implement this interface and pass a
pointer to their implementation to Visio. This interface inherits from
IDispatch and hence IUnknown so client implementation must implement the
methods on those interfaces as well as the method in IVisEventproc. Since
the interface is in the type lib your generator may create a wrapper class
for it. Don't use it. It doesn't do anything useful and probably does
something dumb.
The Visio 2002 SDK contains library code that can be used with AddADvise and
implements IVisEventProc for you. In your SDK install its in
Libraries\Cpp\source\addsink.cpp and Libraries\cpp\source\addsink.h.
The Visio 2002 SDK also has a sample that shows how to use this sink class
in an objected oriented way. Its called GenericMFC. The sample does use
Visiwrap (a legacy Visio wrap mechanism that is not as good as #import
because its too visio specific). The differences between Visiwrap and other
wrapper classes is mostly syntactic so it still a good example of how to use
the code in AddSink.h/cpp. The sample is an add-on BUT that's irrelevant
from the event handling part of this. Add-ons are just easy way's to run
code in Visio in C++. The relevant code for event handling purposes are the
creation of the sink class and calls to AddAdvise in the Run method. If
you're not creating an add-on its needs to go in some other method called,
say InitializeEvents. The other important code to look at is its
HandleVisioEvent method. This is a virtual method inherited from the
VEventHandler class defined in AddSink.h. For non-add-ons that use this,
think about something like:
Class MyEventHandlerClass : public VEventHandler {
/* Class must implement HandlevisioEvent method (virtual method in
VEventHandler). A instance of this class must be passed as the event handler
in the call to CoCreateAddonSinkForHandler (defined in Addsink.h). The class
could also have a public method that handles registering for events using
AddAdvise. */ };
-Visio SDK team.
Thanks,
Mai-lan