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 / perdraw / perdraw.txt < prev    next >
Text File  |  1997-09-09  |  10KB  |  197 lines

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