home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / com / tutsamp / pertext / pertext.txt < prev    next >
Text File  |  1997-09-09  |  10KB  |  194 lines

  1.  
  2. PERTEXT - IPersistStreamInit Persistent Object Server
  3.  
  4.  
  5. SUMMARY
  6. =======
  7.  
  8. PERTEXT is the second sample in a group of samples that covers various
  9. techniques for implementing COM object persistence. The first sample,
  10. PERSERVE, covers persistence by implementing the IPersistStream standard
  11. interface. This sample, PERTEXT, covers persistence by implementing the
  12. IPersistStreamInit standard interface. The third sample, PERDRAW, covers
  13. persistence by implementing the IPersistStorage standard interface. The
  14. fourth sample, PERCLIEN, covers how a client exploits the kinds of
  15. persistence provided the PERSERVE, PERTEXT, and PERDRAW server components.
  16.  
  17. The PERTEXT sample introduces the COTextPage COM object, which
  18. encapsulates the data of an editable page of text. COTextPage objects
  19. expose a set of interfaces whose methods make the objects connectable,
  20. persistent managers of text data. Client access to this data is available
  21. through an ITextPage custom interface. COTextPage implements the ITextPage
  22. interface.
  23.  
  24. The PERTEXT sample keeps a clear architectural distinction between client
  25. and server. Among other things, COTextPage provides no graphical user
  26. interface (GUI), relying instead upon the client for all GUI behavior.
  27.  
  28. The PERCLIEN client provides the GUI display and manages the list of
  29. pages, the contents of which are stored in a compound file that contains
  30. both the contents of the list and of each page in that list. The user of
  31. PERCLIEN can edit the content of two types of pages: text pages and
  32. drawing pages. Text pages have data that the user can edit using a simple
  33. windowed text editor. Drawing pages have drawing data that the user can
  34. edit using free-form, scribble-like functionality based on the earlier
  35. STOSERVE and STOCLIEN samples. Both types of editing are done in separate
  36. client windows. For more information, see PERCLIEN.HTM.
  37.  
  38. Storage in the compound file is achieved because the components provide
  39. persistent COM objects that encapsulate the page list and edited page
  40. data. PERSERVE houses a persistent object that encapsulates the single
  41. page list kept in each compound file containing such pages. PERTEXT houses
  42. a persistent object that encapsulates the edited text data for each text
  43. page. PERDRAW houses a persistent object that encapsulates the drawing
  44. data for each drawing page.
  45.  
  46. The COPageList object in the PERSERVE sample encapsulates the persistent
  47. page list data. COPageList implements the IPersistStream standard
  48. interface to expose control of the page list storage located in the
  49. client-provided stream of a compound file. The COTextPage object in this
  50. PERTEXT sample encapsulates the data of an edited text page. COTextPage
  51. implements the IPersistStreamInit standard interface to expose control of
  52. the text data storage that is located in the client-provided stream of a
  53. compound file. In contrast to these stream-based persistent objects, the
  54. CODrawPage object in the PERDRAW sample encapsulates the persistent
  55. drawing-ink data. CODrawPage implements the IPersistStorage standard
  56. interface to expose control of the drawing-ink data storage located in the
  57. client-provided substorage of a compound file.
  58.  
  59. This code sample focuses primarily on COTextPage's implementation of the
  60. IPersistStreamInit interface to provide stream-based persistence for a COM
  61. object. IPersistStreamInit's InitNew method is the main difference between
  62. the IPersistStream interface used in the PERSERVE sample and the
  63. IPersistStreamInit interface used in the PERTEXT sample. This sample
  64. covers the InitNew method in detail. PERTEXT works with the PERCLIEN code
  65. sample to illustrate the joint use by client and server of
  66. IPersistStreamInit-based persistence.
  67.  
  68. COTextPage's support for object persistence is the primary means of
  69. storing the text page data. COTextPage stores its text data in a
  70. client-provided stream located in a structured storage compound file. The
  71. compound file has a unique format because of the various streams and
  72. storages used. The client identifies these compound files as page files
  73. with a .PAG extension. The client controls the use of the containing
  74. compound file and provides COTextPage with a pointer to the IStream
  75. interface to load and save its text data in the compound file. The IStream
  76. pointer is passed to COTextPage in calls to the IPersistStreamInit
  77. interface methods.
  78.  
  79. COTextPage also exposes an ITextPage custom interface to manipulate the
  80. text that is encapsulated in the text page. ITextPage exposes the
  81. GetLength, GetText, PutText, and Clear methods.
  82.  
  83. COTextPage also supports connectable object features. The
  84. IConnectionPointContainer interface is exposed, an appropriate connection
  85. point is implemented, and an outgoing custom ITextPageSink interface is
  86. declared to send notifications to the client.
  87.  
  88. The two ITextPage and ITextPageSink custom interfaces are declared in
  89. IPAGES.H located in the common INC directory. PAGEGUID.H, which contains
  90. the GUIDs for the interfaces and objects, is also located in that same
  91. directory.
  92.  
  93. The PERTEXT sample uses the CThreaded facility in APPUTIL to achieve
  94. thread safety in the server housing and the class factory. Because the
  95. PERTEXT.DLL is generally accessed from a Single Threaded Apartment (STA)
  96. as an in-process server, COTextPage instances are not coded as thread-safe
  97. using the CThreaded facility. The CLSID_TextPage component is registered
  98. as supporting the apartment threading model.
  99.  
  100. For functional descriptions and a tutorial code tour of the PERTEXT
  101. sample, see the Code Tour section in PERTEXT.HTM. For details on setting
  102. up the programmatic usage of PERTEXT.DLL, see the Usage section in
  103. PERTEXT.HTM. To read PERTEXT.HTM, run TUTORIAL.EXE in the main tutorial
  104. directory and click the PERTEXT lesson in the table of lessons. You can
  105. also do the same thing by double-clicking the PERTEXT.HTM file after
  106. locating the main tutorial directory in Windows Explorer. For more details
  107. on the PERCLIEN client application and how it works with PERTEXT.DLL, see
  108. also PERCLIEN.HTM in the main tutorial directory. You must build
  109. PERTEXT.DLL before running the PERCLIEN sample.
  110.  
  111. The PERTEXT server provides a TextPage component that can create instances
  112. of the COTextPage COM object. COTextPage is housed in the PERTEXT.DLL
  113. in-process server and is made publicly available as a custom COM
  114. component. Like all other servers in this tutorial series, PERTEXT.DLL is
  115. a self-registering COM server. It makes the COTextPage object type
  116. available to clients as the TextPage component in the PERTEXT server using
  117. a CLSID_TextPage registration in the Registry.
  118.  
  119. PERTEXT's makefile automatically registers its TextPage COM component in
  120. the registry, which it must do before clients can use PERTEXT.DLL as a
  121. server for the TextPage component. This self-registration is started in
  122. the makefile using the REGISTER.EXE utility built in the REGISTER sample.
  123. To build or run PERTEXT.DLL, you must build the REGISTER code sample
  124. first.
  125.  
  126. For details on setting up your system to build and test the code samples
  127. in this COM Tutorial series, see TUTORIAL.HTM. The supplied MAKEFILE is
  128. Microsoft NMAKE-compatible. To create a debug build, issue the NMAKE
  129. command in the Command Prompt window.
  130.  
  131.  
  132. Usage
  133. -----
  134.  
  135. To use PERTEXT.DLL, a client program does not need to include PERTEXT.H or
  136. link to PERTEXT.LIB. A COM client of PERTEXT.DLL obtains access solely
  137. through its object's CLSID and COM services. For PERTEXT.DLL, that CLSID
  138. is CLSID_TextPage (defined in PAGEGUID.H in the INC sibling directory).
  139. The PERCLIEN code sample shows how the client obtains this access.
  140.  
  141. PERTEXT.DLL is intended primarily as a COM server. Although it can be
  142. implicitly loaded by linking to its associated .LIB file, it is normally
  143. used after an explicit LoadLibrary call, usually from within COM's
  144. CoGetClassObject function. PERTEXT.DLL is a self-registering in-process
  145. server.
  146.  
  147. The makefile that builds this sample automatically registers the server in
  148. the registry. You can manually initiate its self-registration by issuing
  149. the following command at the command prompt in the PERTEXT directory:
  150.  
  151.   nmake register
  152.  
  153. This assumes that you have a compilation environment set up. If not, you
  154. can also directly invoke the REGISTER.EXE command at the command prompt
  155. while in the PERTEXT directory.
  156.  
  157.   ..\register\register.exe pertext.dll
  158.  
  159. These registration commands require a prior build of both the REGISTER
  160. sample and PERTEXT.DLL.
  161.  
  162. In this series, the makefiles use the REGISTER.EXE utility from the
  163. REGISTER sample. Recent releases of the Microsoft Platform SDK and Visual
  164. C++ include a utility, REGSVR32.EXE, which can be used in a similar
  165. fashion to register in-process servers and marshaling DLLs.
  166.  
  167.  
  168. FILES
  169. =====
  170.  
  171. Files         Description
  172.  
  173. PERTEXT.TXT   This file.
  174. MAKEFILE      The generic makefile for building the PERTEXT.DLL
  175.               code sample of this lesson.
  176. PERTEXT.H     The include file for declaring as imported or defining as
  177.               exported the service functions in PERTEXT.DLL.
  178. PERTEXT.CPP   The main implementation file for PERTEXT.DLL. Has DllMain
  179.               and the COM server functions (for example, DllGetClassObject).
  180. PERTEXT.DEF   The module definition file. Exports server housing functions.
  181. PERTEXT.RC    The DLL resource definition file for the executable.
  182. PERTEXT.ICO   The icon resource for the executable.
  183. SERVER.H      The include file for the server control C++ object.
  184. SERVER.CPP    The implementation file for the server control C++ object.
  185. FACTORY.H     The include file for the server's class factory COM objects.
  186. FACTORY.CPP   The implementation file for the server's class factories.
  187. CONNECT.H     The include file for the connection point enumerator,
  188.               connection point, and connection enumerator classes.
  189. CONNECT.CPP   The implementation file for the connection point enumerator,
  190.               connection point, and connection enumerators objects.
  191. TEXTPAGE.H    The include file for the COTextPage COM object class.
  192. TEXTPAGE.CPP  The implementation file for the COTextPage COM object class
  193.               and the connection points.
  194.