`
`ABB Inc.
`
`EXHIBIT 1006
`
`Page 1 of 221
`
`Page 1 of 221
`
`
`
`
`Applications
`
`Object-Oriented
`
`KRAIG BROCKSCHMIDT ”
`Page 2 of 221
`
`
`
`G:
`
`
`
`The Fast Track
`
`to Building
`
`Powerful
`
`Page 2 of 221
`
`
`
`PUBLISHED BY
`Microsoft Press
`
`A Division of Micr0soft Corporation
`One Microsoft Way
`Redmond, Washington 98052-6399
`
`Copyright © 1994 by Kraig Brockschmidt
`
`All rights reserved. No part of the contents of this book may be reproduced or transmitted
`in any form or by any means without the written permission of the publisher.
`
`Library of Congress Cataloging-in-Publication Data
`Brockschmidt, Kraig, 1968—
`Inside OLE 2 / Kraig Brockschmidt.
`p.
`cm.
`Includes index.
`ISBN 1-55615-618-9
`
`l. Object-oriented programming (Computer science)
`Windows {Computer file)
`I. Title.
`QA76.64.B76
`1993
`005.4‘3--dc20
`
`2. Microsoft
`
`9334953
`CIP
`
`Printed and bound in the United States of America.
`
`123456789AGAG987654
`
`Distributed to the book trade in Canada by Macmillan of Canada, a division of Canada
`Publishing Corporation.
`
`Distributed to the book trade outside the United States and Canada by Penguin Books Ltd.
`
`Penguin Books Ltd, Harmondsworth, Middlesex, England
`Penguin Books Australia Ltd., Ringwood, Victoria, Australia
`Penguin Books NZ. Ltd., 182-190 Wairau Road, Auckland 10, New Zealand
`
`British Cataloging-in—Publication Data available.
`
`Microsoft and MS-DOS are registered trademarks and Visual C++, Windows, and
`Windows NT are trademarks of Microsoft Corporation. Apple is a registered trademark
`and Macintosh is a registered trademark of Apple Computer, Inc. Borland is a registered
`trademark of Borland International. Smalltalk is a registered trademark of Xerox
`Corporation.
`
`Acquisitions Editor: Dean Holmes
`Project Editor: Ron Lamb
`Technical Editor: Seth McEvoy
`
`Page 3 of 221
`
`Page 3 of 221
`
`
`
`
`
`CONTENTS
`
`Prefizce ............................................................ XV
`
`Using the Companion Disks ............................................ xxii
`
`SECTION I
`
`WINDOWS OBJECTS
`
`CHAPTER 1
`
`AN OVERVIEW OF OLE 2 ....................................... 3
`
`Windows Objects: The Component Object Model ........................ 5
`Objects and Interfaces ............................................... 8
`Structured Storage and Compound Files ............... .
`.
`.
`.
`. .......... 12
`Uniform Data Transfer and Notification .............................. 15
`Notification ................................................... 17
`
`. ............................. 17
`.
`Data Objects and the Clipboard .
`................................ 17
`Data Objects and Drag-and-Drop
`Data Objects and Compound Documents ........................ 18
`Data Objects and DDE ......................................... 19
`Compound Documents: Object Embedding ........................... 19
`Compound Documents: Object Linking and Monikers .................. 21
`Compound Documents: In—Place Activation (Visual Editing)
`.
`.
`. ....... 23
`Automation .
`. .................................................. 24
`
`CHAPTER 2
`
`CONVENTIONS, C++, AND SAMPLE CODE .................. 27
`
`.............. . ....... 27
`To C or Not to C (with Apologies to Shakespeare)
`User-Defined Types: C++ Classes
`.............................. 29
`Access Rights .
`.
`. .......... .
`.
`. ........................ .
`33
`Single Inheritance
`............................................. 34
`Virtual Functions and Abstract Base Classes .
`.
`,
`_
`.
`.
`.
`.
`.
`.
`.
`.
`.
`.
`.
`.
`.
`.
`.
`37
`
`Multiple Inheritance .......................................... 39
`Sample Code ...................................................... 41
`Include Files: The INC Directory
`.
`.
`.
`.
`.
`.
`.
`. .............. 42
`Libraries: The LIB Directory ................................. .
`43
`The BUILD Directory .......................................... 43
`Three Amigos: BttnCur, CizmoBar, and StatStrip ........... .
`.
`.
`.
`44
`Class Libraries: The CLASSLIB Directory .
`.
`.
`.
`.
`.
`.
`.
`.
`.
`.
`.
`.
`.
`.
`i
`.
`.
`,
`.
`.
`. 45
`
`.
`
`Page 4 of 221
`
`Page 4 of 221
`
`
`
`INSIDE OLE2
`-——————_—__—__
`
`. 48
`.
`Interface Templates: The INTERFAC Directory ............... .
`Chapter Sources: The CHAPxx Directories
`........................ 48
`Cosmo: A Graphical Editor (with Apologies to No One in Particular)
`.
`. 49
`Patron: A Page Container (with Apologies to Merriam-Webster)
`..... 51
`Building and Testing Environment .................... .
`.
`.
`. 54
`
`.
`
`CHAPTER 3
`
`OBJECTS AND INTERFACES .
`
`l
`
`l .............................. 57
`
`The Ultimate Question to Life, the Universe, and Objects
`........ 58
`t
`,
`.
`.
`.
`(with Apologies to Douglas Adams)
`........
`.
`.
`Windows Objects vs. C++ Objects .
`.
`.
`.
`....................... 64
`Let’s Go Traveling ............................................. 64
`Other Differences Between Windows Objects and C++ Objects
`..... 67
`A Simple Object in C and C++: RECTEnumemtor
`‘
`.
`. ................ .
`. 70
`RECTEnummwr and the IEnumRECT Interface ......
`.
`.
`.
`_
`..... 72
`
`. ............. 94
`,
`_
`.
`.
`.
`.
`_
`.
`Creating the RECTEnumcmtor Object
`Using an IEnumRECT Pointer
`. .......................... .
`.
`95
`Reference Counting ................................................ 96
`My Kingdom for Some Optimizationsl
`................................ 98
`Call-Use-Release .................................................. 100
`anknoum,theRootofAllEVil
`.............. ..
`......
`.
`.. 101
`Querylnterfacevs. Inheritance ........................................ 103
`Querylnteaj‘acg Properties and Interface Lifetimes
`.
`.
`.......... . 104
`Some Data Types and Calling Conventions ........................... 106
`STDMETHOD and Associates .................................. 106
`HRESULT and SCODE ........................................ 107
`Globally Unique Identifiers: GUIDs, IIDs, CLSIDS ........... .
`. 109
`OLE 2 Interfaces and API Functions ................................. 1 10
`Custom Interfaces ............. .
`.
`.
`............ .
`...... 112
`Interfaces vs. API Functions .................................... 112
`
`, ........ 1 13
`.
`. ............
`.
`.
`What Is a Windows Object? (Reprise)
`Summary...
`.. ............ ._._.
`.. .................... 114
`
`CHAPTER 4
`
`COMPONENT OBJECTS
`. 117
`. ................ .
`.
`(THE COMPONENT OBJECT MODEL)
`Where the Wild Things Are (with Apologies to Maurice Sendak)
`....... 1 19
`The New Application for Windows Objects .........
`.
`.
`________ 121
`Enlarge the Message Queue ............ .
`.
`................ .
`122
`Verify the Library Build Version
`.............. . ............
`123
`Call CoImtz'alz'ze or Oldmtz'alize ............ .
`.
`.
`.
`.
`.
`.
`.
`.
`.
`t
`.
`,
`.
`124
`Call CoUm‘nitialize or OleUninitiaiize
`...................... 125
`
`vi
`
`E.—
`
`Page 5 0f221
`
`Page 5 of 221
`
`
`
` Contents
`
`.
`
`......................... 126
`Memory Management and Allocator Objects
`Component Objects from Class Identifiers: A Component User .
`.
`.
`,
`.
`.
`.
`138
`#inciude glad]; and Precompiled Headers
`.
`. .................... 148
`Instantiate a Component Object ................................ 149
`Manage the Object and Call CoFreeUnusesz'bmries
`.
`.
`.
`.
`........ 152
`Implementing a Component Object and a Server .
`.
`.
`.
`.
`. ........
`. 153
`RegisterCLSIDs
`.
`. ..
`..... .
`.
`.174
`.
`.
`.
`.
`.
`Implement the Glass Factory .
`.
`.
`.
`.
`............... . 176
`.
`.
`.
`.
`Expose the Class Factory .....
`............................ 178
`Provide an Unloading Mechanism .
`.
`.
`.
`.
`,
`.
`t
`.
`_
`.
`_
`_
`.
`.
`.
`.
`.
`.
`. 182
`Cosmo’s Polyline as a DLL Object ................................... 187
`Object Reusability .
`_
`.
`.
`.
`.
`_
`.
`.
`.
`.
`.
`.
`.
`.
`.
`.................. . 191
`Case 1: Object Containment
`........................... .
`.
`.
`. 194
`Case 2: Object Aggregation
`.
`_
`.
`.
`_
`.
`.
`. ...................... 195
`Summary.........,........--.
`.
`.._....___.201
`
`.
`
`.
`
`.
`
`S E C T I O N
`
`I
`
`I
`
`OBJECT-ORIENTED SYSTEM FEATURES:
`
`FILES AND DATA TRANSFER
`
`C H A P T E R
`
`5
`
`. 205
`STRUCTURED STORAGE AND COMPOUND FILES ........
`Motivation ...................................................... 208
`
`...... 209
`.
`Patron Files with the jitters ..................... .
`The Decaffeinated Alternative .................................. 211
`
`............. 213
`Energy Boosts Without the jitters: Compound Files
`Features of Compound Files ............................. .
`.
`.
`.
`_
`. 215
`Stream, Storage, and LockBytas Objects
`.................... .
`.
`. 215
`Element Naming .
`........ t
`.
`.......
`.
`.
`.
`.
`_
`_
`.
`.
`_
`_
`. 217
`AccessModes. ................................
`217
`
`.
`.
`
`Transacted Storages
`Incremental Access .
`Shareable Elements
`
`.
`
`.....
`.
`.
`.
`.
`.
`.
`.
`.
`.
`..........
`
`. ........................ 219
`.
`.
`. ............ _
`.
`.
`.
`.
`.
`.
`.
`. 220
`,
`.
`t .................. . ..
`.
`.
`.
`. 222
`
`.............................. 223
`Compound File Objects and Interfaces
`Storage Objects and the [Storage Interface ........................ 223
`Stream Objects and the IStream Interface ............. .
`....... 227
`LockBytas Objects and the ILockBytas Interface
`.
`.
`.
`.
`.
`.
`.
`.
`.
`.
`.
`.
`.
`. 229
`.
`.
`Compound Files in Practice .....
`.
`. ................
`.
`.
`_
`.
`. 233
`Simple Storage: Cosmo ........................................ 234
`Pulling Rabbits from a Hat with STGM_CONVERT .
`.
`.
`.
`........ 240
`Streams vs. Files
`.
`.
`.
`.
`........ .
`. ........................ . 241
`
`Page 6 of 221
`
`vii
`
`Page 6 of 221
`
`
`
`fl
`
`INSIDE OLE2
`—————————-____.___—_—______
`
`Complex Compound Files: Patron .................................. 244
`The Root Storage and Temporary Files .......................... 263
`Managing Substorages ........ . ..........
`. ................... 264
`Multilevel Commits ........................................... 265
`File Save As Operations
`....................................... 288
`Low-Memory Save As Operations
`.......
`.
`. .................. 269
`Streams as Memory Structures
`.
`.
`.
`.
`.
`.
`.
`.
`.
`.
`.
`.
`.
`...... 271
`.
`Other OLE 2 Technologies and Structured Storage .................... 272
`The IPerszlrtStomge, [PersistStream and [PersistFile Interfaces ........... 273
`A Heavy Dose of Protocol with IPersistStamge ...................... 275
`Of Component Users and [PersistStomg-e: Component Cosmo ........ 278
`Of Component Objects and IPersistStomge: Polyline .
`.
`.
`.
`.
`.
`.
`.
`.
`.
`..... 281
`Compound File Defragmentation .
`.
`.
`. .................. _
`.
`....... 288
`Summary ................................ .
`.
`. ............ .
`.
`. 297
`
`CHAPTER 6
`
`UNIFORM DATA TRANSFER USING DATA OBJECTS ......... 299
`What Is a Data Object?
`............................................ 301
`New and Improved Ultra-Structures!
`............................. . 302
`Data Objects and the IDamObject Interface ............................ 308
`FORMATETC Enumerators and Format Ordering
`. ................. 312
`Component Data Objects ................................. .
`.
`.
`.
`. 318
`Some CDataObject Features
`.
`.
`.
`.
`, ............ .
`. ............ 329
`Implementing IDataObject ..... . ................................ 330
`A (Component) Data Object User .........
`, .................... .
`331
`Advising and Notification with Data Objects .
`.
`.
`.
`.
`. ................. 345
`Establishing an Advisory Connection .
`.
`.
`, ....................... 351
`Sending Notifications as a Data Object .......................... 355
`Special Considerations for Remoted Notifications . ........... .
`.
`. 359
`Inside the Advise Sink ........................................ 360
`IDataObject as a Standard for Object Data Transfer ..................... 363
`View Objects and the IViewObject Interface .
`.
`. .................... .
`.
`.
`. 365
`IViewObjectxme .............................................. 367
`Rendering for a Specific Device
`. .................. .
`......... 369
`Drawing into a Metafile
`.
`.
`. ................................. 370
`Aborting Long Repaints ....................................... 370
`Other IViewObject Member Functions
`........
`.
`.
`.
`. ............. 371
`.
`IViewObject and Notification .
`.
`.
`.
`.
`.
`.
`.
`.
`. .................. .
`372
`Freeloading from OLE2.DLL ....................................... 373
`IDaraObject and DDE .
`.
`.
`.
`.
`.
`.
`. .................. .
`............ 383
`Summary ........
`.
`.
`. ................ .
`.
`_
`, .................. 385
`
`V‘“
`
`Page 7 of 221
`
`Page 7 of 221
`
`
`
` Contents
`
`0 H A P T E R 7
`
`...... 387
`.
`.
`CLIPBOARD TRANSFERS USING DATA OBJECTS .
`The OLE 2 Clipboard Protocol ..................................... 389
`But All I Want to Do 15 Copy Some Simple Data!
`..................... 391
`A Data Transfer Component Object ............................. 393
`If You Already Have a Data Object...Component Cosmo
`.
`.
`.
`.
`.
`.
`. 405
`If You Already Have Extensive Clipboard-Handling Code .......... 407
`Simple Data Source and Consumer: Cosmo ..................
`. 408
`Startup/Shutdown ............................................ 408
`Copy/Cut .................................................... 409
`Enabling Edit/Paste ........................................... 41 1
`Paste ........................................................ 412
`Paste Special and a Functional Patron ............................... 414
`The Paste Special Dialog Box and the OLE2UI Library
`. 416
`Tenant Creation, Paste
`........................................ 420
`Saving and Loading Tenants ................ .
`.
`.
`.
`.
`. .......... 424
`Copy and Cut
`, 425
`Summary ....................... .
`. .................... . 426
`
`.
`
`.
`
`.
`
`c H A P T E R 8
`
`. 429
`DRAG—AND—DROP OPERATIONS USING DATA OBJECTS ..
`Sources and Targets: The Drag-and—Drop Transfer Mode]
`.............. 430
`.
`A Step-by—Step Drag-and-Drop Implementation: Cosmo .
`.
`.
`.
`.
`.
`.
`.
`_ 439
`Design and Implement Drop Target User Feedback ............... 454
`Implement a Drop Target Object and the IDmmeget Interface .
`.
`.
`. 456
`IDropTargetrflngnter .................................
`456
`IqubTargetangOver
`.
`.
`.
`.
`.
`.
`,
`.
`.
`.
`.
`. ....................... 459
`IDmpTargetxDmgLeave
`................... .
`.
`.
`.
`.
`.
`.
`,
`.
`.
`.
`.
`.
`.
`.
`.
`.
`.
`. 460
`IDropTarget ::Dr0p .............................................. 46 I
`Register and Revoke the Drop Target Object ................... 462
`Design and Implement Drop Source User Feedback ............. , 464
`Determine the Pick Event ...................................... 464
`
`. 465
`Implement a Drop Source Object and the IDropSource Interface
`466
`Call DoDngmp .............. . ............................
`Intermission ..................................................... 468
`Advanced Drag-and—Drop: Feedback and Scrolling in Patron .
`. .......... 469
`.
`Tenant Pick Regions and Drop Sourcing .
`.
`.
`.
`.
`_
`.
`_
`.
`.
`.
`.
`.
`.
`..... 470
`More Advanced Drop Target Hit-Testing ......................... 472
`A Feedback Rectangle ......................................... 474
`Scrolling the Page ............................ .
`.....
`.
`.
`. 477
`Summary .. ................ . .................................. 482
`
`Page 8 of 221
`
`ix
`
`Page 8 of 221
`
`
`
`INSIDE OLE2
`
`
`SECTION Ill
`
`COMPOUND DOCUMENTS: OLE
`
`CHAPTER 9
`
`.
`
`.
`
`COMPOUND DOCUMENTS
`..........
`AND EMBEDDED CONTAINERS .
`.
`. ...................
`_
`.
`Compound Document Mechanisms
`.
`.
`.............. .
`.
`.
`.
`.
`.
`.
`.
`The Passive State
`.
`.
`.
`.
`.
`.
`The Loaded State ................................ .
`Case IzlancServer......,.
`_
`_
`.
`.
`..
`.
`.. ................
`Case 2: InProcHandler ....................... _
`. .. .
`.
`.
`. ..
`Case 3: The Default Handler ......
`.
`.
`_
`.
`.
`.
`.
`.
`.
`.
`.
`.
`_
`_
`Loading the Object: All Cases
`.
`.
`............ .
`Drawing the Object ...........................................
`The Running State ............................................
`Mommy, Daddy, Where Do New Objects Come From? _
`.
`.
`.
`.
`.
`.
`The Structure of a Container Application .........
`.
`.
`.
`Embedding Containers Step by Step ............
`Call Initialization Functions at Startup and Shutdown .
`Define Sites and Manage Site Storage .............
`.
`.
`.
`.
`Implement Site Interfaces and Add Site Variables .
`.
`.
`Implement IAdviseSink
`........... .
`.
`,
`.
`. ..............
`Implement [OIeCZientSite .......... .
`.
`. ...................
`Implement Site Shading ..................... .
`.
`.
`Invoke the Insert Object Dialog Box
`.......
`_
`.
`.
`. .........
`Call OleUHmertObject ........................ . ................
`Call OleCreate or OleCreatemeFz'le ................................
`Initialize the Object ...........................................
`Draw and Print Objects ........................................
`Activate Objects and Add the Object Verb Menu
`...............
`Mouse Double—Clicks ............ .
`.
`_ ....................
`ObjectVerb Menu .......................... .
`.
`.
`The Right Mouse Button Pop-Up Menu ..........................
`Create Objects from the Clipboard and Drag-and—Drop Transfers .
`.
`.
`Copy and Source Embedded Objects .....
`Close and Delete Objects ......................................
`Save and Load the Document with Embedded Objects
`_
`.
`.
`.
`.....
`.
`Handle Iconic Presentations (Cache Control)
`.
`.
`.
`.
`.
`.
`.......
`Summary ..
`.
`.. ................... .
`.
`. ..................
`
`.
`
`Page 9 of 221
`
`Page 9 of 221
`
`
`
`Contents
`
`c H A P T E B 10
`
`COMPOUND DOCUMENTS AND
`
`EMBEDDED OBJECT SERVERS (EXES)
`
`. 565
`
`The Structure of a Server Application ............................... 566
`Linking Support and Mini-Servers vs. Full-Servers
`.......... 568
`Version Numbers
`............................ 569
`Installation ................................................... 569
`
`Embedding Servers Step by Step .................................... 570
`Call Initialization Functions at Startup and Shutdown ........... 571
`Create Registration Database Entries ............
`_ 572
`Implement and Register a Class Factory ........................ 577
`Implement an Initial Object With IUnknown .................... . 586
`Implement the IPersistStamge Interface .
`.
`.
`.
`.
`.
`. 594
`Implement the IDataObject Interface ............................ 601
`Implement the IOleObject Interface
`.
`.
`.
`.
`.
`.
`.
`.
`. ______________ 610
`Modify the Server’s User Interface .............................. 629
`Send Notifications ............................................ 633
`
`.................... 637
`(Full-Servers) Add OLE 2 Clipboard Formats
`(Optional) MDI Servers, User Interface, and Shutdown .
`.
`.
`.
`.
`.
`.
`.
`.
`.
`.
`. 638
`Summary ........................................................ 639
`
`G H A P T E R 1 1
`
`. 641
`IN—PROCESS OBJECT HANDLERS AND SERVERS .......
`The Structure of In—Process Modules
`................................ 641
`
`.......................................... 644
`Why Use a Handler?
`Why Use an In-Process Server?
`................................. 646
`Why Not Use an In-Process Server?
`............................. 647
`Delegating to the Default Handler .................................. 648
`IOleObject ..................................................... 649
`IDamObject ................................................... 651
`IPersistStomge (on the Cache)
`.............................. 652
`IViewObject ................................................... 652
`Implementing an Object Handler ................................... 653
`Obtain a Default Handler [Unknoam ............................. 656
`
`....... 659
`.
`Expose Default Handler Interfaces in Querylmmface .
`Implement [PersistStomge
`.
`.
`. ................................ 662
`Implement IOleObject::GetExtem .
`.
`.
`.....
`.
`t
`.
`. ................ 666
`Implement IViewObject .........................
`.
`. 668
`Synchronized Swimming with Your Local Server .................... . 674
`Year-End Bonuses ................................................. 678
`
`. 679
`Notes on Implementing an In-Process Server ...............
`Summary
`.......................... 692
`
`Page 10 of 221
`
`xi
`
`Page 10 of 221
`
`
`
`INSIDE OLE2
`—-————-—————__.______________
`
`CHAPTER 12
`
`MONIKERS AND LINKING CONTAINERS ..................... 695
`Will Someone Please Explainjust What a Moniker Is? .
`.
`.
`.
`........
`.
`. 698
`Moniker Classes
`.............................................. 699
`Where Do I Get Monikers? ..................................... 703
`Step-by—Step Linking Container
`.................................... 704
`Enable Links from Insert Object ................................ 705
`Enable Linking from Clipboard and Drag-and—Drop Operations
`.
`.
`.
`. 709
`Paste Link and Paste Special Commands
`........
`.
`. ......... 711
`Drag-and—Drop Linking Feedback .......... .
`. ............ .
`713
`.
`Test Your Linking ...................... .
`.
`.
`.
`.
`_
`. ......... 715
`Implement the Show Objects Command ......................... 717
`Manage a File Moniker, Call IOZeObjecthezMoniker,
`and Implement IOkCliemSite:GetMoniker ..................... 722
`The Links Dialog Box and the IOleUILkaonmmer Interface ........ 727
`Invoke the Links Dialog Box ................................... 744
`Update Links on Loading a D0cument .......... .
`. ........... 747
`Summary ........................................................ 751
`
`CHAPTER 13
`
`MONIKER BINDING AND LINK SOURCES .................... 753
`Moniker Binding Mechanisms ...................................... 755
`A Simple Linked Object: Single File Moniker
`............ ,
`.
`.
`.
`. 756
`A Linked Object with a Composite Filei'Item Moniker
`............. 758
`Binding a Composite FileflteMIItemfflemHEem... Moniker
`.
`.
`.
`.
`.
`_
`.
`.
`i
`. 762
`Bind Contents ................................................ 764
`The Running Object Table ..................................... 765
`A Simple Link Source: Cosmo .
`.
`i
`. ................................. 766
`Create, Register, and Revoke a File Moniker
`.
`.
`.
`.
`.
`. ............ 767
`.
`Provide Link Source Formats in Data Transfer
`........... .
`.
`. 770
`Implement the IPerszlstFile Interface ........................... .
`. 774
`Implement [OleOIy'ecthetMomker and IOEeObjecthetMoniker .........
`777
`Complex Linking and Linking to Embeddings
`.
`. ............ .
`.
`.
`. 779
`Why Linking to Embedding? ..................... .
`_
`........ 780
`Create and Manage the Composite Moniker
`.
`.
`.
`................ 782
`Source the Composite Moniker ................................. 787
`Implement a Glass Factory for Document Objects with IPersisth'le
`‘
`.
`. 789
`Implement IOleItemContainer for Each Item Moniker
`, ............. 792
`Summary .......
`,
`.
`. ..............
`.
`. .............. .
`.
`.
`.
`.
`. 806
`
`xii
`
`Page 11 of 221
`
`Page 11 of 221
`
`
`
`_
`
` Contents
`
`0 H A P 'I' E H
`
`14
`
`CONVERSION, EMULATION,
`AND COMPATIBILITY WITH OLE 1
`
`.................... .
`
`.
`
`.
`
`809
`
`The Convert Dialog Box for Containers .............................. 810
`Support a Convert Menu Item and Invoke the Convert Dialog Box
`. 813
`Handle the Convert To Case .......... . ......... .
`.
`. ........... 816
`Handle the Activate As Case
`.
`.
`.
`. ........................ .
`.
`.
`. 818
`
`. ....................... 820
`.
`.
`.
`Handle Display As Icon Changes .
`Conversion Between Servers ........................................ 822
`
`....... 823
`.
`.
`.
`.
`.
`,
`.
`.
`Registration Database Entries for Conversion
`[PersistStomge Modifications .
`. ................................ 828
`OLE 1 Embedded Object Conversion and Emulation ................. 828
`Notes on OLE 1 Compatibility for Containers
`.
`.
`.
`.
`. .......... .
`.
`.
`. 883
`OLE 1 Server Quirks ................................. . ....... 833
`File Conversion ...........................................
`834
`
`Summary ............. .
`
`.
`
`.
`
`._
`
`.
`
`.
`
`.
`
`........
`
`839
`
`S E c T I O N
`
`I V
`
`COMPOUND DOCUMENTS:
`
`IN-PLACE ACTIVATION
`
`C H A P T E R 15
`
`VISUAL EDITING:
`
`. 843
`IN—PLACE ACTIVATION AND IN—PLACE CONTAINERS .
`. 845
`.
`I
`.
`.
`Motivations and the Guts of an In—Place Session
`.
`.
`.
`.
`.
`......
`Where Does It All Start? ............... . .................... . 846
`An Innocent Little Dal/er!) ...................................... 848
`
`.
`
`.
`
`.
`
`.
`
`Activating In-Place ....................................... .
`.
`. 849
`Manipulations of an Active Object
`. ....................... .
`.
`. 857
`Pulling the Plug: Deactivation .
`.
`.
`.
`.
`.
`.
`.
`.
`.
`.
`.
`_
`_
`.
`.
`_
`.
`.
`.
`_ 880
`Active vs. UI Active and Inside-Out Objects ..................... 861
`Yes, This Actually Does Work ................................... 881
`In-Place Container Step By Step
`.................................... 862
`Prepare the Container ......................................... 883
`Implement Skeletal In-Place Container Interfaces ................. 865
`Activate and Deactivate the Object
`.
`.
`.
`. ..................... 875
`Mix-a—Menu: Shaken, Not Stirred ............................... 877
`NegotiateToolSpace.........,... .....__.. .
`..
`..
`882
`
`Page 12 of 221
`
`Xi“
`
`Page 12 of 221
`
`
`
`INSIDE OLE2
`
`.
`.....
`.
`Provide In-Place Accelerators and Focus
`. ..........
`Round the Corners: Other Miscellany
`Summary ........ .
`.
`. ........
`.
`.
`. ............ .
`
`. ........... 892
`.
`.
`..... 895
`........
`_
`905
`
`.
`
`c H A P 'r E n 16
`
`lN—PLACE ACTIVATION FOR
`. 907
`COMPOUND DOCUMENT OBJECTS .................... .
`In-Place Objects Step by Step ......................... ,
`.
`.
`.
`..... 908
`Drivers, Prepare Your Objects ................................ . 909
`Implement Skeletal Iii-Place Object Interfaces
`and Object Helper Functions .............................. 912
`Implement Simple Activation and Deactivation ................. . 915
`Assemble and Disassemble the Menu .........
`.
`............ . 927
`Create and Destroy Iii-Place Tools
`..........................
`. 934
`Manage and Process Accelerators .............................. 938
`Rounding Third...and Heading for Home ,
`.
`.
`.
`.
`.
`.
`.
`.
`........ 940
`Where ln-Place Activation Can Take Us
`.............. .
`.
`.
`.
`.
`.
`_
`.
`. 950
`Summary..... ..............
`............ 955
`
`Index
`
`_
`
`.
`
`.
`
`................... .
`
`. ......................... 957
`
`xiv
`
`Page 13 of221
`
`Page 13 of 221
`
`
`
`"II-1
`
`5-
`
`
`
`'{1‘
`
`-.
`
`
` . a
`: :3,
`llWA.”
`\L.\i~“LL.
`\\\K\\\\\\\~\LL1$\
`
`€<\\k‘fi\‘
`
`-»
`--|
`‘1?.1
` l
`
`-
`
`
`1
`
`'1
`
`q:l'Il
`
`
`El
`
`'
`
`.
`
`il
`
`ill.
`
`i
`
`PREFACE
`
`Give me afish andyoufeed mefor a day.
`
`Teach me tofish and youfeed mefor a lifetime.
`
`A proverb
`
`This is a book about fish. But because without knowing how to catch them,
`you’d eventually starve, it’s also about fishing. The fish are all those pieces of
`information that you need as a developer in order to exploit OLE 2 features in
`your application. Teaching you to fish involves describing why the specific
`pieces you are using were designed and what path they lay toward the future.
`Of course, you always need a reason to keep fishing even if you’re currently
`well fed, so at the beginning of each chapter I will attempt to motivate you
`enough to read it.
`It has been said that authors write books not so that they will be un-
`derstood, but so that they themselves understand. Certainly this work has
`been such an experience for me. When I started working with OLE 2 in the
`middle of 1992 as part of my job in Microsoft’s Developer Relations Group, I
`saw the technology as merely a way to create applications that support what is
`called “Compound Documents,” as OLE version 1 was. This attitude was well
`accepted at Microsoft because OLE 2 was a refinement of OLE 1; in fact, the
`OLE 2 design specifications are organized around 3 Compound Document
`core with a number of other technologies hanging off the sides to solve the
`most critical problems exposed in OLE 1.
`For a number of months, I plodded through prerelease information
`about OLE 2 to create some sample applications to demonstrate compound
`documents. With the help of various members of the OLE 2 development
`team, with whom I’ve worked closely for all this time, I gave a number of
`classes inside and outside of Microsoft to help others use OLE 2 to create
`Compound Document applications. In the back of my mind something was
`telling me that there was much more to OLE 2 than I had originally per-
`ceived, but it was very hard to break away from equating OLE 2 and Com-
`pound Documents because every available piece of documentation made the
`two terms synonymous.
`
`Page 14 of 221
`
`XV
`
`Page 14 of 221
`
`
`
`INSIDE OLE2
`
`In the first few Weeks of January, 1993, I started to see that, in the process
`of solving the most important problems in OLE l, the OLE 2 architects had
`actually created a much larger system for object-oriented programming
`under Windows. I began to see that OLE 2 has technologies that are separate
`from the true Compound Document technologies. In fact, I started to see ex-
`actly how one might use those other technologies without ever coming into
`contact with Compound Documents. I was not the first person to realize this.
`In fact, OLE 2 was actually designed this way, but this aspect of the design
`unfortunately was lost somewhere between the minds of the OLE 2 architects
`and the actual OLE 2 Design Specification. But I was slowly beginning to
`rediscover the elegant underlying architecture of the entire group of tech-
`nologies. My position within Microsoft allowed me to explore OLE 2 in depth
`and even to browse the OLE 2 sources, letting me truly get “Inside OLE 2.”
`One Sunday afternoon in mid-January, 1993, while doing something
`totally unrelated to OLE 2, I achieved what Eric Maffei (editor of Microsoft Sys-
`tems journal) describes as “OLE Nirvana.” All the little subtechnologies in
`OLE 2 fell into place and I saw clearly, after six months of mental fog, what
`OLE 2 was all about. I realized that you could exploit very small pieces of OLE
`2 in incremental steps and that the best way to communicate the entire vision
`was to write a book. I quickly fired up my notebook computer and spent the
`next three hours pounding out the outline. The book you now hold follows
`that original outline closely.
`My goal in writing this book was to provide an organization for OLE 2 in
`such a way that each chapter depends solely on information in previous chap-
`ters, with no dependencies on later chapters. Because OLE 2 is not a tech—
`nology for writing whole applications (because we still use many Windows
`API functions), I had the luxury of concentrating on OLE 2’s features and the
`way you use those features in your applications. I have presented the material
`a little at a time, in order to help you solidify your understanding of that
`building block before moving on. I hope the book takes you on an evolution-
`ary path, on which the work you do early in the book will be reusable in work
`you do in the later stages.
`This same idea is present even within any given chapter, where I have
`provided finely detailed step-by-step instructions for implementing specific
`features and where each step depends on the prior steps but not on any later
`step. This sort of process enables you to add a little code, compile your appli-
`cation, and actually see something working! Personally, I find the incre-
`mental feedback of this sort of process extraordinarily motivating. In fact,
`
`xvi
`
`Page 15 of221
`
`Page 15 of 221
`
`
`
`P reface
`
`it makes programming fun, and that is refreshing in this day and age of “seri-
`ous” professional programmers. I got into computers because hacking out
`some BASIC code was exhilarating. I hope I can bring some of that back
`through this book.
`OLE 2 is the first step in the evolution of Windows from the function
`call—based operating system we have today to an object-oriented operating
`system in the future. The object model you will learn in this book will be a
`part of Windows programming for a long time, and I hope it will help you
`develop a definite edge in your programming career. Because OLE 2 is a first
`step, it is going to seem utterly alien much of the time. But you need to learn
`how to fish sometime if you are ever going to feed yourself. While you are
`learning the skills of a master angler, this book will help you catch enough
`fish to keep you from starving.
`
`Who Can Use This Book
`
`I mentioned earlier that OLE 2 is not a technology for writing an entire appli-
`cation. To use OLE 2, you must be familiar with how to write an application
`for Windows. I will not describe how to use any of the existing Windows API
`functions, nor will I attempt to describe any intricate details about Windows
`itself. Our focus in this book is strictly on OLE 2.
`Therefore, I assume that you are already familiar with programming in
`the Windows environment and that you have at least a working knowledge of
`the Windows API. In addition, because we are talking about object-oriented
`programming here, a knowledge of C++ is helpful, but not required. In fact,
`C++ knowledge can at times be a hindrance to understanding the object
`model in OLE 2. Although the samples in this book are written in C++, I‘ve
`kept them very much like standard C Windows programs. Chapter 2 contains a
`short discussion of the C++ 1 use in all the book’s samples, from a C program-
`mer’s perspective (which was my own perspective when I started writing this
`book).
`
`This book is not only for programmers, however. Each chapter is struc-
`tured so that a person who designs application architectures can read the first
`few sections and understand how the mechanisms in OLE 2 work without hav-
`
`ing to work through the details of code. The first 5 to 20 pages of each chapter
`discuss architecture, leaving exact details about writing code to the latter
`parts of the chapter. So, if you want an in—depth look at how OLE