How Visio Exposes Objects

3 4

The objects that Microsoft Visio exposes are Component Object Model (COM) objects. The concepts of an interface on an object and a reference to an interface are fundamental to understanding COM. If you use the C++ files provided with Visio and described later in this chapter, you won't need to program at this level. It can help, however, to have a general understanding of what's happening behind the scenes.

To illustrate an interface on an object and a reference to an interface, here is a simple example, expressed in pseudocode:

 ipAppObj = <reference to an interface on a Visio Application object> //Get documents collection ipDocsObj = ipAppObj->Documents() //Get first document ipDocObj = ipDocsObj->Item(1) 

Notice the similarities between the assignments in this example and object assignments in Microsoft Visual Basic. You can extrapolate from this example to use the Microsoft Visual Basic for Applications (VBA) programming information elsewhere in this guide. Given a reference to an interface on a Document object, the program can obtain, in like fashion, a reference to an interface on a Page object, and then a Shape object, and so on. The properties and methods provided by these objects are exactly the same as those discussed in earlier chapters of this guide.

The program state after this code executes is shown in the following illustration, which uses the common conventions for showing COM objects. The controlling program has obtained references to interfaces on three objects exposed by Visio. The arrows are the references, the circles are the interfaces, and the boxes inside the Visio instance are the objects.

Figure 28-1.  The program state after getting a <b>Document</b> object.(<b>A</b>) A program controlling a Visio instance. (<b>B</b>) COM interfaces. (<b>C</b>) An instance of Visio.

Figure 28-1 The program state after getting a Document object.(A) A program controlling a Visio instance. (B) COM interfaces. (C) An instance of Visio.

COM provides many kinds of interfaces, such as those that support persistent data storage. A COM interface pointer refers to data that represents the object that owns the interface. An interface also refers to an array of functions that perform the actions defined in that interface for that object. After you have a reference to an interface on an object, you can call the methods defined in that interface for that object.

The interfaces that Visio exposes are dual interfaces. In a dual interface, the first entries are identical to the entries in a standard IDispatch interface, the principal interface used to implement Automation. The IDispatch methods are followed by entries that correspond to the methods and properties exposed by the object. A dual interface has methods or properties that can be called either indirectly through IDispatch methods or directly through the "dual" methods.

IDispatch functions define a protocol that allows late binding—that is, binding that occurs at run time—between Automation controllers and Automation servers. However, if an Automation server provides a type library and implements dual interfaces (as Visio does), it enables early binding—that is, binding that occurs at compile time. This typically results in improved performance by the Automation controller, because the program makes fewer calls at run time to invoke a method. For details about IDispatch and dual interfaces, see the Automation documentation in the Microsoft Platform SDK on MSDN (msdn.microsoft.com).



Developing Microsoft Visio Solutions 2001
Developing Microsoft Visio Solutions (Pro-Documentation)
ISBN: 0735613532
EAN: 2147483647
Year: 2004
Pages: 180

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net