Share via


Conserve: Connectable COM Objects in an In-Process Server

Note   To use this sample, you must first build the Register sample.

The Conserve sample shows how to construct a connectable COM object, COBall, in a thread-safe in-process server. To expose connectable object features, COBall implements the standard COM interface, IConnectionPointContainer. COBall also implements the custom interface, IBall, that is introduced in the Freserve sample.

The principal focus of Conserve is the connectable object support in COBall and how connected clients are notified of ball events. Conserve works with the Conclien client sample.

Conserve's COBall implements a virtual moving ball similar to the one coded in the Freserve sample. However, rather than Freserve's free-threaded COM object, Conserve houses COBall in an apartment model server. COBall defines the internal logic of a moving ball that exists within a specified two-dimensional bounding rectangle. COBall provides only a description of a ball. It is up to the client to create a graphical representation based on the data managed in COBall.

Clients move the virtual ball using its IBall interface. COBall's internal logic will bounce the ball when it collides with a boundary. The client can obtain the ball's current position, size, and color to permit display of the ball's moving image. The client can also use the connection facilities of COBall to receive notifications of ball bounce events. The Conclien sample uses these connection facilities to produce various sounds when the ball bounces.

Conserve uses the CThreaded facility in Apputil for thread safety, as in the Freserve sample. COBall objects are derived from the CThreaded class and inherit its OwnThis and UnOwnThis methods. These methods allow only one thread at a time to have access to the Conserve server and to COBall objects managed by the server.

See the parent topic, COM Tutorial Samples, to download global tutorial files or any HTML files about this sample.

Building SDK Samples

This sample uses the following keywords:

addref; addregnamedvalue; advise; bouncebottom; bounceleft; bounceright; bouncetop; canunloadnow; cballthread; cfball; checkbounce; cimpiball; cimpiclassfactory; cimpiconnectionpointcontainer; clear; clone; coball; coconnectionpoint; coenumconnectionpoints; coenumconnections; createinstance; cserver; cxform; defined; delete_pointer; dllcanunloadnow; dllgetclassobject; dllmain; dllregisterserver; dllunregisterserver; enumconnectionpoints; enumconnections; failed; findconnectionpoint; findslot; findthread; getball; getconnectioninterface; getconnectionpointcontainer; getcurrentthreadid; getdimensions; getdirection; getlasterror; getmodulefilename; getposition; getslot; getusername; lock; lockserver; lrandom; lstrcat; lstrcpy; lstrlen; max; memset; move; next; notifysinks; objectsdown; objectsup; ownthis; point; queryinterface; regclosekey; regcreatekeyex; regdeletekey; regopenkeyex; regsetvalueex; release; release_interface; reset; rgb; scale; setdimensions; setdirection; setposition; setregkeyvalue; skip; stdentry_; stdmethodimp_; stringfromguid2; succeeded; text; trans; unadvise; unicodeok; unlock; unownthis; wsprintf