COMOBJ - COM Objects in a DLL SUMMARY ======= This samples introduces COM objects. An object is a software construct that encapsulates or packages some data and some public methods that operate on that data. The data is often said to be "hidden" while the methods are exposed as the chief means to access the data. At compile time, programming languages provide varying degrees of syntactic support to express objects. For example, the C++ language offers a Class syntactic construct to express an abstract type (or class) of object. However, this C++ Class construct does allow for public access to an object's data. An object class is an abstraction that refers to an open-ended set of potential objects of the same specific kind. Objects are real things that occupy memory with their data and code instantiated in live binary form. The 'object' term typically refers to the runtime behavior of the this real software thing. A COM object is a kind of object that originated with Microsoft's Component Object Model (COM). COM objects completely hide their data and expose their methods through a construct called an interface. A COM interface is a grouping of related methods that is uniquely identified for all programs and all time (by an Interface ID). Interfaces are used to encapsulate COM object feature sets. The most fundamental feature set in COM gives COM objects their nature as COM objects. The IUnknown interface exposes this feature set in several methods (AddRef, Release, and QueryInterface) that determine the common behavior governing all COM object lifetimes and how interfaces on COM objects are properly acquired. Outside users of a COM object can only use the object by acquiring one of its interfaces. This acquisition of an interface is achieved by obtaining a pointer to the COM object's implementation of the interface. COM objects "know" about the interfaces they expose to clients and can provide pointer references to the interface implementations. Likewise, COM objects know about how many interface references they have handed out to clients and can thus control their own lifetime. When no references remain, the object normally removes itself from memory and ceases to exist. The COMOBJ DLL offers several car-related COM object classes. Because COMOBJ.DLL supports no object handlers, class factories, full in-process servers, or marshshaling, it is not a full-blown COM Server. Rather, it is a primitive precursor to an COM in-process server. This DLL exposes the following COM objects: COCar, COUtilityCar, and COCruiseCar. Appropriate create functions are exported from this DLL: CreateCar, CreateUtilityCar, and CreateCruiseCar. In this tutorial, COMOBJ works with the COMUSER code sample to show how an EXE client (COMUSER.EXE) calls COM object creation services and manipulates the COM objects that are created. For functional descriptions and a tutorial code tour of COMOBJ, see the Code Tour section in COMOBJ.HTM. For details on setting up the programmatic usage of COMOBJ, see the Usage section in COMOBJ.HTM. To read COMOBJ.HTM, run TUTORIAL.EXE in the main tutorial directory and click the COMOBJ lesson in the table of lessons. You can also achieve the same thing by clicking the COMOBJ.HTM file after locating the main tutorial directory in the Windows Explorer. See also COMUSER.HTM in the main tutorial directory for more details on the COMUSER client application and how it works with COMOBJ.DLL itself. You must build COMOBJ.DLL before building COMUSER. The makefile for COMOBJ copies the necessary COMOBJ.H, COMOBJ.LIB, and COMOBJ.DLL files to the appropriate sibling directories once the files are built. The .H goes to \INC, the .LIB goes to \LIB, and the .DLL goes to \COMUSER. In general, to set up your system to build and test the code samples in this COM Tutorial series, see TUTORIAL.HTM for details. The supplied makefile is Microsoft NMAKE-compatible. To create a debug build, issue the NMAKE command at the command prompt. Usage ----- COMOBJ is a DLL that you can access from .EXE modules either by performing an explicit LoadLibrary call or implicitly loading the DLL by linking to its associated import library (.LIB) file. In either case, you need to include COMOBJ.H to declare the functions that are defined as exported in the COMOBJ DLL. In this lesson, a representative COMUSER.EXE application is provided to illustrate the programmatic use of COMOBJ.DLL. COMUSER is built in the COMUSER lesson (in sibling directory COMUSER). See below for more details. FILES ===== Files Description COMOBJ.TXT This file. MAKEFILE The generic makefile for building the COMOBJ.DLL code sample. COMOBJ.H The include file for declaring as imported or defining as exported the service functions in COMOBJ.DLL. COMOBJ.CPP The main implementation file for COMOBJ.DLL. Has DllMain and the COM Object creation functions. CAR.H The include file for the COCar COM object class. CAR.CPP The implementation file for the COCar COM object class. UTILCAR.H The include file for the COUtilityCar COM object class. UTILCAR.CPP The implementation file for the COUtilityCar COM object class. CRUCAR.H The include file for the COCruiseCar COM object class. CRUCAR.CPP The implementation file for the COCruiseCar COM object class. COMOBJI.H The include file for the internal class declarations and resource identifier definitions for resources stored inside the COMOBJ.DLL. COMOBJ.RC The DLL resource definition file. COMOBJ.ICO The icon resource.