Monikers Jim Fawcett CSE 775 Distributed Objects Spring
Monikers Jim Fawcett CSE 775 – Distributed Objects Spring 2007
References • About the only detailed reference is: − Inside OLE, Second Edition, Kraig Brockschmidt, Microsoft Press, 1995 − http: //msdn 2. microsoft. com/enus/library/ms 691261. aspx
Monikers • Here’s what Microsoft MSDN Library has to say about monikers: − Monikers are objects that implement the IMoniker interface and are generally implemented in DLLs as component objects. There are two ways of viewing the use of monikers: as a moniker client, a component that uses a moniker to get a pointer to another object; and as a moniker provider, a component that supplies monikers identifying its objects to moniker clients. − OLE uses monikers to connect to and activate objects, whether they are in the same machine or across a network. A very important use is for network connections. They are also used to identify, connect to, and run OLE compound document link objects. In this case, the link source acts as the moniker provider and the container holding the link object acts as the moniker client.
What is a Moniker? • Monikers contain the logic necessary to find a currently running object by name (CLSID, URL). They can recreate and initialize an object instance in case there is no running instance. • Monikers provide persistent encapsulated names for: − Files − Database queries − Specific range of spreadsheet cells • Each moniker binds to one specific object
So What is a Moniker? • A Moniker is a COM object that: − Implements the IMoniker interface − Provides persistent storage for descriptive text − Knows how to: • Instantiate and/or access its object • Cause some process to act on its object − Provides a “universal” interface so clients don’t need to know the details of what it does. • Very like the way the STL iterators shield clients from container details.
So What is a Moniker? • In the Windows OS, a moniker is anything that implements a link, e. g. : − File associations (a specific extension is linked to an executable) − Short cuts − Bookmark to some place in a document − Link to a chart inserted in a word document
What is a Moniker? • A moniker is a COM object that implements the IMoniker interface, which, in turn inherits the IPersist. Stream Interface: − Some of its IPersist. Stream methods are: • IPersist: Get. Class. ID • IPersist. Stream: Is. Dirty, Load, Save, Get. Size. Max − Monikers add the methods: • Binding: Bind. To. Object, Bind. To. Storage • Building and Reducing Composite Monikers: Reduce, Compose. With, Enum, Inverse, Relative. Path. To • Naming: Get. Display. Name, Parse. Display. Name • Other methods: Is. Equal, Hash, Is. Running, Get. Time. Of. Last. Change, Is. System. Moniker
How are Monikers Used? • Create a COM object and initialize its state from persistant storage, as a single operaton. • Download a remote object’s server, register it, and instantiate the object, as happens with Active. X objects on a webpage. • There a number of System Monikers that do these kinds of operations. • System Monikers: − File monikers: reconstitute object from file − Class monikers: bind to an object’s class factory − Item monikers: bind to a part of a larger object, e. g. , a range of cells in a spreadsheet.
Class Moniker • • • Call Create. Class. Moniker Call Bind. Moniker That returns pointer to class factory Use that to create instance Use the instance Class monikers are placed in the per process activation table by Register. Class. Object, used by out-proc servers to support COM activation.
File Moniker • Call Create. File. Moniker • Call Bind. To. Object to bind file to an object − CLSID in file, or based on file extension • File. Moniker: − creates an instance of object − Calls Query. Interface asking for IPersist. File interface and uses its Load method to initialize the object • File moniker creates an initialized object
Code Samples • In the code samples that follow, you will see applications of: − Class moniker − File moniker − Custom moniker
End of Presentation
- Slides: 12