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 / comobj / comobj.txt < prev    next >
Text File  |  1997-08-05  |  6KB  |  111 lines

  1.  
  2. COMOBJ - COM Objects in a DLL
  3.  
  4.  
  5. SUMMARY
  6. =======
  7.  
  8. This samples introduces COM objects.
  9.  
  10. An object is a software construct that encapsulates or packages some
  11. data and some public methods that operate on that data.  The data is often
  12. said to be "hidden" while the methods are exposed as the chief means to
  13. access the data.  At compile time, programming languages provide varying
  14. degrees of syntactic support to express objects. For example, the C++
  15. language offers a Class syntactic construct to express an abstract type
  16. (or class) of object. However, this C++ Class construct does allow for
  17. public access to an object's data. An object class is an abstraction that
  18. refers to an open-ended set of potential objects of the same specific
  19. kind. Objects are real things that occupy memory with their data and code
  20. instantiated in live binary form. The 'object' term typically refers to
  21. the runtime behavior of the this real software thing.
  22.  
  23. A COM object is a kind of object that originated with Microsoft's
  24. Component Object Model (COM). COM objects completely hide their data and
  25. expose their methods through a construct called an interface.  A COM
  26. interface is a grouping of related methods that is uniquely identified for
  27. all programs and all time (by an Interface ID).  Interfaces are used to
  28. encapsulate COM object feature sets.  The most fundamental feature set in
  29. COM gives COM objects their nature as COM objects. The IUnknown interface
  30. exposes this feature set in several methods (AddRef, Release, and
  31. QueryInterface) that determine the common behavior governing all COM
  32. object lifetimes and how interfaces on COM objects are properly acquired.
  33.  
  34. Outside users of a COM object can only use the object by acquiring one of
  35. its interfaces.  This acquisition of an interface is achieved by obtaining
  36. a pointer to the COM object's implementation of the interface.  COM
  37. objects "know" about the interfaces they expose to clients and
  38. can provide pointer references to the interface implementations. Likewise,
  39. COM objects know about how many interface references they have handed out
  40. to clients and can thus control their own lifetime. When no references
  41. remain, the object normally removes itself from memory and ceases to
  42. exist.
  43.  
  44. The COMOBJ DLL offers several car-related COM object classes. Because
  45. COMOBJ.DLL supports no object handlers, class factories, full in-process
  46. servers, or marshshaling, it is not a full-blown COM Server. Rather, it is
  47. a primitive precursor to an COM in-process server.
  48.  
  49. This DLL exposes the following COM objects: COCar, COUtilityCar, and
  50. COCruiseCar. Appropriate create functions are exported from this DLL:
  51. CreateCar, CreateUtilityCar, and CreateCruiseCar.
  52.  
  53. In this tutorial, COMOBJ works with the COMUSER code sample to show how an
  54. EXE client (COMUSER.EXE) calls COM object creation services and manipulates
  55. the COM objects that are created.
  56.  
  57. For functional descriptions and a tutorial code tour of COMOBJ, see the
  58. Code Tour section in COMOBJ.HTM. For details on setting up the
  59. programmatic usage of COMOBJ, see the Usage section in COMOBJ.HTM. To read
  60. COMOBJ.HTM, run TUTORIAL.EXE in the main tutorial directory and click the
  61. COMOBJ lesson in the table of lessons. You can also achieve the same thing
  62. by clicking the COMOBJ.HTM file after locating the main tutorial directory
  63. in the Windows Explorer. See also COMUSER.HTM in the main tutorial
  64. directory for more details on the COMUSER client application and how it
  65. works with COMOBJ.DLL itself. You must build COMOBJ.DLL before building
  66. COMUSER. The makefile for COMOBJ copies the necessary COMOBJ.H,
  67. COMOBJ.LIB, and COMOBJ.DLL files to the appropriate sibling directories
  68. once the files are built. The .H goes to \INC, the .LIB goes to \LIB, and
  69. the .DLL goes to \COMUSER.
  70.  
  71. In general, to set up your system to build and test the code samples in
  72. this COM Tutorial series, see TUTORIAL.HTM for details. The supplied
  73. makefile is Microsoft NMAKE-compatible. To create a debug build, issue the
  74. NMAKE command at the command prompt.
  75.  
  76. Usage
  77. -----
  78.  
  79. COMOBJ is a DLL that you can access from .EXE modules either by performing
  80. an explicit LoadLibrary call or implicitly loading the DLL by linking to its
  81. associated import library (.LIB) file. In either case, you need to include
  82. COMOBJ.H to declare the functions that are defined as exported in the COMOBJ
  83. DLL. In this lesson, a representative COMUSER.EXE application is provided
  84. to illustrate the programmatic use of COMOBJ.DLL. COMUSER is built in the
  85. COMUSER lesson (in sibling directory COMUSER). See below for more details.
  86.  
  87.  
  88. FILES
  89. =====
  90.  
  91. Files       Description
  92.  
  93. COMOBJ.TXT  This file.
  94. MAKEFILE    The generic makefile for building the COMOBJ.DLL code sample.
  95. COMOBJ.H    The include file for declaring as imported or defining as
  96.             exported the service functions in COMOBJ.DLL.
  97. COMOBJ.CPP  The main implementation file for COMOBJ.DLL. Has DllMain
  98.             and the COM Object creation functions.
  99. CAR.H       The include file for the COCar COM object class.
  100. CAR.CPP     The implementation file for the COCar COM object class.
  101. UTILCAR.H   The include file for the COUtilityCar COM object class.
  102. UTILCAR.CPP The implementation file for the COUtilityCar COM object class.
  103. CRUCAR.H    The include file for the COCruiseCar COM object class.
  104. CRUCAR.CPP  The implementation file for the COCruiseCar COM object class.
  105. COMOBJI.H   The include file for the internal class declarations and
  106.             resource identifier definitions for resources stored inside
  107.             the COMOBJ.DLL.
  108. COMOBJ.RC   The DLL resource definition file.
  109. COMOBJ.ICO  The icon resource.
  110.  
  111.