1 / 108

OLE Object Linking & Embedding

OLE Object Linking & Embedding. 主講人:虞台文. Content. Basic Concept OLE Technologies Component Object Model (COM) Object IDs and Interface IDs System Registry Object Interfaces Object Polymorphism and Reusability Using COM Objects Memory Management Desktop Management.

gala
Download Presentation

OLE Object Linking & Embedding

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. OLEObject Linking & Embedding 主講人:虞台文

  2. Content • Basic Concept • OLE Technologies • Component Object Model (COM) • Object IDs and Interface IDs • System Registry • Object Interfaces • Object Polymorphism and Reusability • Using COM Objects • Memory Management • Desktop Management

  3. OLEObject Linking & Embedding Basic Concept

  4. Knowing what interfaces an object provides then we know what can be done by the object, i.e., the features the object possesses. Objects and Interfaces What functions these objects provide? How to access these objects?

  5. Knowing what interfaces an object provides then we know what can be done by the object, i.e., the features the object possesses. Objects and Interfaces To access the objects you need to know • What interfaces they provide? • How to operate their interfaces?

  6. How to achieve embedding and linking to objects from different sources? OLE Object Linking and Embedding Systematically, these objects must be equipped with dedicated interfaces for object embedding and linking.

  7. In-Place Editing

  8. ActiveX Controls

  9. Exercises • What are the differences between object linking and object embedding? You also give an example using Microsoft Office. • What is OLE automation? • Design a web page making use an ActiveX control to display multimedia content. • What are the differences between Java applets and ActiveX controls.

  10. OLEObject Linking & Embedding OLE Technologies

  11. Overview • Object oriented programming (OOP) • effective in developing reusable software components. • How to build an object-oriented operating system? • Microsoft solution  OLE. • OLE’s contribution • Facilitates and enables the integration of components. • Works independently of programming languages through a binary standard. • Provides multiple interfaces to access an objects.

  12. Why OLE? • Need network applications and distributed computation. • Need interoperability between applications. • Software revision version handling • To use a system service in a polymorphic fashion • Software integration • components developed using different languages • components running in separate processes or on separate machines • Self-expressibility of software • Tradition service models makes it nearly impossible for the service provider to express new, enhanced, or unique capabilities to potential clients in a uniform fashion.

  13. Component Software • Software component objects are much like integrated circuit (IC) component, and component software is the integrated circuitry of tomorrow. • OLE offers a solution and future extensible standards and mechanism to enable software developers to package their functionality, and content, into reusable components, like an integrated circuit. • Plug and play OLE allows you to buy a binary component and reuse it, plugging into it through its external interfaces.

  14. OLE is no longer given a version number. OLE Defined • OLE is a unified environment of object-based services with the capability of • customizing those services; and • arbitrarily extending the architecture through custom services, with the overall purpose of • enabling rich integration between components.

  15. Function calls to object interfaces Component Clients and Severs Sever Client Object Object How to define Objects & Interfaces?

  16. Object-Based Components: COM • Component Object Model (COM) is a binary standard for software componentry introduced by Microsoft in 1993. • It is used to enable interprocesscommunication and dynamic object creation in any programming language that supports the technology. • The term COM is often used in the software development world as an umbrella term that encompasses the OLE, OLE Automation, ActiveX, COM+ and DCOM technologies.

  17. Classical Objects vs. OLE Objects • Classic Objects • Encapsulation • Polymorphism • Inheritance • OLE Objects • Encapsulation • Polymorphism • Reusabilility  Source code must be available  Using off-the-shelf objects directly

  18. Methods (member functions) Object Implementation • Any object can be seen as a set of • properties (data members or content); and • methods (member functions). Object Properties (data members, content)

  19. Interface pointer lpVtbl Pointer to Function1 Private object data Pointer to Function2 Pointer to Function3 . . . A client accesses a specific feature of an object through a particular interface. Hence, an interface is, in fact,a group of semantically related functions toexpose a specific feature. OLE Objects & OLE Interfaces • The nature of an OLE object, then, is not expressed in how it is implemented internally but rather in how it is exposed externally. Interface function table, or vtable Object Implementation of interface functions

  20. Interface pointer lpVtbl Pointer to Function1 Private object data Pointer to Function2 Pointer to Function3 . . . A client accesses a specific feature of an object through a particular interface. OLE Objects & OLE Interfaces • The nature of an OLE object, then, is not expressed in how it is implemented internally but rather in how it is exposed externally. Can be implemented using any languages A client access the object only through the interface pointer. Interface function table, or vtable Object Implementation of interface functions

  21. Object A client accesses a specific feature of an object through a particular interface. Simplified Notation on OLE Objects & OLE Interfaces Interfaces are drawn as plug-in jacks extending from the object. Interface pointer

  22. . . . A client accesses a specific feature of an object through a particular interface. An object may have multiple features meaning that it may provide multipleinterfaces. Multiple Interfaces Interfaces are drawn as plug-in jacks extending from the object. Object Interface_1 pointer Interface pointer Interface_2 pointer Interface_n pointer

  23. . . . A client accesses a specific feature of an object through a particular interface. An object may have multiple features meaning that it may provide multipleinterfaces. Multiple Interfaces How to know what interfaces that a object provides? Interfaces are drawn as plug-in jacks extending from the object. The answer is COM. Object Interface_1 pointer Interface_2 pointer Interface_n pointer

  24. OLETechnologies

  25. OLETechnologies

  26. OLEObject Linking & Embedding Component Object Model (COM)

  27. COM Fundamentals • A binary standard for function calling between components. • A provision for strongly-typed groupings of functions into interfaces. • A base interface providing: • A way for components to dynamically discover the interfaces implemented by other components. • Reference counting to allow components to track their own lifetime and delete themselves when appropriate. • A mechanism to uniquely identifycomponents and their interfaces. • A "component loader" to set up component interactions and additionally in the cross-process and cross-network cases to help manage component interactions

  28. . . . COM Objects and Interfaces In convention, the names of COM interface start with character ‘I’. IUnknown AV-Device Object IOnOff IAudioControl IDVDPlayControl

  29. . . . IUnknown The root of all evil IUnknown AV-Device Object IOnOff IAudioControl IDVDPlayControl

  30. . . . interface IUnknown { virtual HRESULT QueryInterface(REFIID riid, void **ppvObject)=0; virtual ULONG AddRef(void)=0; virtual ULONG Release(void)=0; }; IUnknown The root of all evil IUnknown IUnknown is the base interface of every custom COM interface. AV-Device Object IOnOff IAudioControl IDVDPlayControl

  31. . . . interface IUnknown { virtual HRESULT QueryInterface(REFIID riid, void **ppvObject)=0; virtual ULONG AddRef(void)=0; virtual ULONG Release(void)=0; }; IUnknown The root of all evil IUnknown IUnknown is the base interface of every custom COM interface. AV-Device Object IOnOff // Example interface IOnOff : IUnknown { virtual HRESULT On()=0; virtual HRESULT Off()=0; }; IAudioControl IDVDPlayControl

  32. QueryInterface QueryInterface AddRef AddRef Release Release Pointer to fn1 Pointer to fn2 Pointer to fn3 Pointer to fn4 Function Tables for COM Interfaces Function table for IUnknown Function table for another interface A pointer to this interface can also be used as a pointer to IUnknown

  33. OLEObject Linking & Embedding Object IDs and Interface IDs

  34. IUnknown IOnOff AV-Device Object IAudioControl . . . IDVDPlayControl IUnknown interface IUnknown { virtual HRESULT QueryInterface(REFIID riid, void **ppvObject)=0; virtual ULONG AddRef(void)=0; virtual ULONG Release(void)=0; }; IUnknown In COM, every interface is also an IUnknown interface.

  35. IUnknown IOnOff AV-Device Object IAudioControl . . . IDVDPlayControl IUnknown::QueryInterface interface IUnknown { virtual HRESULT QueryInterface(REFIID riid, void **ppvObject)=0; virtual ULONG AddRef(void)=0; virtual ULONG Release(void)=0; }; Query an interface by giving the reference of the interface ID. Who assign the ID? In COM, every interface is also an IUnknown interface.

  36. GUID Globally Unique Identifier • GUID is a special type of identifier used in software applications in order to provide a reference number which is unique in any context (hence, "Globally"). • It is a 128-bit randomly generated number developed by Microsoft based on a carefully developed algorithm • The chance of generating duplicate GUIDs in two different places at different times, even without a network card, is about the same as two random atoms in the universe colliding to form a small California avocado mated to a New York City sewer rat. In other words, don't worry about it. • Represented in form of {F9043C85-F6F2-101A-A3C9-08002B2F49FB}

  37. GUID Globally Unique Identifier • GUID is a special type of identifier used in software applications in order to provide a reference number which is unique in any context (hence, "Globally"). • It is a 128-bit randomly generated number developed by Microsoft based on a carefully developed algorithm • The chance of generating duplicate GUIDs in two different places at different times, even without a network card, is about the same as two random atoms in the universe colliding to form a small California avocado mated to a New York City sewer rat. In other words, don't worry about it. • Represented in form of {F9043C85-F6F2-101A-A3C9-08002B2F49FB} typedefstruct _GUID { ULONG Data1; WORD Data2; WORD Data3; UCHAR Data4[8]; } GUID, *PGUID;

  38. UUID Generation GUID Generator (GUDIGEN.EXE)

  39. GUID Generator (GUDIGEN.EXE) // {920EA478-7DEA-4176-861E-823418B23191} DEFINE_GUID(<<name>>, 0x920ea478, 0x7dea, 0x4176, 0x86, 0x1e, 0x82, 0x34, 0x18, 0xb2, 0x31, 0x91);

  40. Class IDs (CLSID) and Interface IDs (IID) CLSID_Xxx or IID_Xxx // {920EA478-7DEA-4176-861E-823418B23191} DEFINE_GUID(<<name>>, 0x920ea478, 0x7dea, 0x4176, 0x86, 0x1e, 0x82, 0x34, 0x18, 0xb2, 0x31, 0x91); <<name>>

  41. Class IDs (CLSID) and Interface IDs (IID) • CLSIDs are GUIDs which are used by Windows to identify software components without having to know their “name” • Naming convention CLSID_Xxx, e.g., // GUID for HTML viewer is: {25336920-03F9-11cf-8FD0-00AA00686F13} DEFINE_GUID(CLSID_HTMLViewer, 0x25336920, 0x3f9, 0x11cf, 0x8f, 0xd0, 0x0, 0xaa, 0x0, 0x68, 0x6f, 0x13); • IIDs are GUIDs associated with interfaces • Naming convention IID_IXxx, e.g., // {00000000-0000-0000-C000-000000000046} DEFINE_GUID(IID_IUnknown, 0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46); // {00000001-0000-0000-C000-000000000046} DEFINE_GUID(IID_IClassFactory, 0x00000001, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);

  42. Function Purpose CoCreateGuid Allocates a new GUID IsEqualGUID Compares two GUIDs for equivalence IsEqualCLSID Typesafe version of IsEqualGUID for CLSIDs IsEqualIID Typesafe version of IsEqualGUID for IIDs StringFromCLSID Typesafe conversion of a CLSID to a text string StringFromIID Typesafe version of StringFromCLSID for IIDs StringFromGUID2 Converts a GUID to a text string, storing the string in a caller-allocated buffer CLSIDFromString Converts a text string to a typesafe CLSID IIDFromString Typesafe version of CLSIDFromString for IIDs COM API Functions for GUIDs

  43. #include <initguid.h> • Any code that ever refers to any GUID, be it a CLSID or an IID, must include a standard OLE header file, INITGUID.H, once and only once in the entire compilation of a DLL or an EXE.

  44. OLEObject Linking & Embedding System Registry

  45. RegEdit.EXE or RegEdt32.EXE OLE information is installed

  46. CLSID Registration OLE information is installed all the information about component classes is installed

  47. Object IDs all the information about component classes is installed

  48. Example:Microsoft Word Document

  49. Example:Microsoft Word Document Convert to new version

  50. Example:Microsoft Word Document Convert to new version

More Related