<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-2252742141481837423</id><updated>2011-11-27T15:18:42.178-08:00</updated><category term='ATL COM'/><title type='text'>ATL COM Tutorial (ActiveX Template Library and COM</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://atlcomtutorial.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2252742141481837423/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://atlcomtutorial.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>sandy</name><uri>http://www.blogger.com/profile/02503582209971047801</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>6</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2252742141481837423.post-6079745045110381329</id><published>2008-08-24T22:51:00.001-07:00</published><updated>2008-12-23T00:13:42.077-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ATL COM'/><title type='text'>Reusability In COM-II (Aggregation)</title><content type='html'>&lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;One way to reuse a component within another              component is using &lt;i&gt;containment&lt;/i&gt;. Another              way to do so is using &lt;i&gt;aggregation&lt;/i&gt;. In &lt;i&gt;containment&lt;/i&gt; the outer component makes use              of the inner component, but does not directly expose the inner              component to its clients. The outer component can choose to use the              inner component to implement some of its functionality. If the outer              component decides to implement one or more of the interfaces of the              inner component it must provide a wrapper for every method in the              exposed interfaces. The method wrappers can simply call the inner              component’s methods directly, or they can perform additional              tasks such as validating parameters, recording usage, or otherwise              extending the inner component’s interface.&lt;/span&gt; &lt;/p&gt; &lt;span style="font-size:100%;"&gt;             &lt;dir&gt;&lt;/dir&gt;  &lt;/span&gt;  &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Sometimes, it’s more              convenient to expose the interfaces of the inner object directly,              without writing a collection of wrappers. This is aggregation. A              client creates the outer object, and when it asks &lt;b&gt;QueryInterface( )&lt;/b&gt; for an interface supported by the inner              object, it gets passed a pointer to the inner object’s interface. When we use containment or aggregation the client does not know that              there are actually two separate components acting in unison. We may              as well have more than two objects. The outer component can              aggregate several different components. Similarly, the inner              component can aggregate another component into itself.&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Aggregation has one distinct              advantage over containment: it requires much less knowledge of the              inner component on the part of the person implementing the outer              component. Also, bypassing the wrapper layer makes the component              that bit more efficient. The disadvantages of aggregation are that              the inner (aggregated) object must be specially written so that it              can be aggregated, and that the inner object can only be implemented              in a DLL that is loaded directly into the same apartment as the              outer object. There is no cross-apartment, cross-process or              cross-machine aggregation.&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Let us now understand              aggregation with the help of some concrete example. Suppose we have              a component that knows how to swap mouse buttons and set the time              interval between two clicks of the mouse button. We can develop              another component which uses this existing component and              additionally also manage mouse trails. The existing component              becomes the inner component. Given below is the procedure for              building these components and a client that accesses the              functionality of both the components.&lt;/span&gt; &lt;/p&gt; &lt;b&gt;&lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Creating The Inner              Component&lt;/span&gt;&lt;/p&gt; &lt;/b&gt;&lt;span style="font-size:100%;"&gt; &lt;p align="justify"&gt;The process of creating              components in ATL consists of three steps:&lt;/p&gt; &lt;/span&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;b&gt;(a) Creating              Module:&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;       To create a module              the Developer Studio provides an ATL COM AppWizard. Carry out the              following steps:&lt;/span&gt;&lt;/p&gt; &lt;ul&gt;&lt;li&gt;     &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Select              ‘New’ from the ‘File’ menu.&lt;/span&gt;   &lt;/p&gt;&lt;/li&gt;&lt;li&gt;     &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Select ‘ATL COM              AppWizard’ as the project. Type ‘Inner’ as the              project name and click ‘OK’ to continue.&lt;/span&gt;   &lt;/p&gt;&lt;/li&gt;&lt;li&gt;     &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Select type of module as              ‘Dynamic Link Library’, click ‘Finish’.&lt;/span&gt; &lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;   &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;b&gt;(b) Adding Component To The              Module&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;dir&gt;  &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;To add component to the module              we can use ‘ATL Object Wizard’. Carry out the following              steps for adding a component using this wizard:&lt;/span&gt;&lt;/p&gt;&lt;/dir&gt;   &lt;ul&gt;&lt;li&gt;   &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Select ‘Insert | New ATL                  Object’ menu item. This would display the ‘ATL                  Object Wizard’&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;   &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Select ‘Simple Object’ from                  the various object categories and click on ‘Next’.&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;   &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;A ‘ATL Object Wizard                  Properties’ dialog is displayed.&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;   &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Enter the ‘Short Name’ as                  ‘Mouse’. As soon as you do this all other edit                  controls would be filled automatically. Click on OK.&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;  &lt;p align="justify"&gt;&lt;b&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;(c) Adding Methods To The              Component&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;dir&gt;  &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;The component that has been              added does not contain any functionality. To provide functionality              we should add two methods named &lt;b&gt;SwapButton(              )&lt;/b&gt; and &lt;b&gt;SetDoubleclicktime( )&lt;/b&gt; as              indicated below.&lt;/span&gt;&lt;/p&gt;&lt;/dir&gt;   &lt;ul&gt;&lt;li&gt;   &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Switch to class view tab. Select the                  interface ‘IMouse’ and click the right mouse button.                  From the menu that pops up, select ‘Add Method’.&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;   &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;In the ‘Add Method to                  Interface’ dialog specify the method name as                  ‘SwapButton’ and leave the parameters edit control                  empty.&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;   &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Click on ‘OK’.&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;   &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Adding the &lt;b&gt;SwapButton( )&lt;/b&gt; method creates a function definition in                  ‘Mouse.cpp’ as shown below:&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;  &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;STDMETHODIMP CMouse::SwapButton(              )&lt;br /&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;// TODO: Add your              implementation code here&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;return              S_OK ;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;}&lt;/span&gt;&lt;/p&gt;   &lt;ul&gt;&lt;li&gt;   &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Add the following code to the   SwapButton( ) method by double clicking                  on this method from the Class view tab:&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;  &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;mousestatus = !mousestatus              ;&lt;/span&gt;&lt;/p&gt;   &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;SystemParametersInfo ( SPI_SETMOUSEBUTTONSWAP, mousestatus,NULL,NULL )              ;&lt;/span&gt;&lt;/p&gt;   &lt;ul&gt;&lt;li&gt;   &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;From the class view tab add a private                  variable mousestatus of type BOOL to                  the CMouse class. Initialize this                  variable to FALSE in the constructor of CMouse class.&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;   &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;On similar lines add another method                  called &lt;b&gt;SetDoubleclicktime( )&lt;/b&gt;. Its                  code is given below:&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;  &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;STDMETHODIMP CMouse::SetDoubleclicktime ( long time )&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;{&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;AFX_MANAGE_STATE(AfxGetStaticModuleState( ) )&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;// TODO: Add your implementation code              here&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;SystemParametersInfo ( SPI_SETDOUBLECLICKTIME, time, NULL, NULL )              ;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;return S_OK ;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;}&lt;/span&gt;&lt;/p&gt; &lt;b&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Creating The Outer              Component&lt;/span&gt;&lt;/p&gt; &lt;/b&gt;&lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;The procedure for creating the              outer component is same as that for creating the inner component.              First create a module called ‘Outer’. Insert a component              called ‘MouseTrails’ in it and then add a method called &lt;b&gt;SetMouseTrails( )&lt;/b&gt; to it.&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;This methods is shown              below:&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;STDMETHODIMP CMouseTrails::SetMouseTrails ( int trails              )&lt;/span&gt;&lt;/p&gt;   &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;{&lt;/span&gt;&lt;/p&gt;   &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;AFX_MANAGE_STATE ( AfxGetStaticModuleState( ) )&lt;/span&gt;&lt;/p&gt;   &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;// TODO: Add your implementation code              here&lt;/span&gt;&lt;/p&gt;   &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;SystemParametersInfo ( SPI_SETMOUSETRAILS, trails, NULL, NULL )              ;&lt;/span&gt;&lt;/p&gt;   &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;return S_OK              ;&lt;/span&gt;&lt;/p&gt;   &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;}&lt;/span&gt;&lt;/p&gt;   &lt;ul&gt;&lt;li&gt;   &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Include the file ‘inner.h’                  in ‘mousetrail.h’ as shown below:&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;  &lt;dir&gt;  &lt;p&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;# include              "..\inner\inner.h"&lt;/span&gt;&lt;/p&gt; &lt;/dir&gt;   &lt;ul&gt;&lt;span style="font-size:100%;"&gt;&lt;li&gt;   &lt;p align="justify"&gt;Add a private member variable called &lt;i&gt;m_agg &lt;/i&gt;in the outer class from the class                  view tab:&lt;/p&gt;&lt;/li&gt;&lt;/span&gt;&lt;/ul&gt;  &lt;p&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial Narrow;font-size:100%;color:#0000ff;"&gt;       &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;   &lt;/span&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;CComPtr&lt;iunknown&gt; m_agg ;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;dir&gt;  &lt;p align="justify"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;This variable would be used to              hold the IUnknown pointer that we are              going to get back from the aggregate when we create it.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;/dir&gt;   &lt;ul&gt;&lt;span style="font-size:100%;"&gt;&lt;li&gt;   &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Add the following macro to the file                  ‘MouseTrails.h’&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/span&gt;&lt;/ul&gt;  &lt;span style="font-size:100%;"&gt;  &lt;/span&gt;&lt;dir&gt;  &lt;p&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;DECLARE_GET_CONTROLLING_UNKNOWN( )&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;/dir&gt;   &lt;ul&gt;&lt;span style="font-size:100%;"&gt;&lt;li&gt;   &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Add the following function to the                  ‘MouseTrails.h’ file.&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/span&gt;&lt;/ul&gt;  &lt;span style="font-size:100%;"&gt;  &lt;/span&gt;&lt;dir&gt;  &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;HRESULT FinalConstruct( )&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:100%;"&gt;  &lt;/span&gt;&lt;blockquote&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;HRESULT hr              ;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;CLSID clsid              ;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;CoInitialize ( NULL )              ;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;hr = CLSIDFromProgID ( OLESTR (              "inner.Mouse" ), &amp;amp;clsid )&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;if (              FAILED ( hr ) )&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;         ::MessageBox ( 0, "", "CLSIDFromProgID failed",              0 ) ;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;hr = CoCreateInstance ( clsid, GetControllingUnknown( ), CLSCTX_INPROC, IID_IUnknown, ( void ** )              &amp;amp;m_agg ) ;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;if ( FAILED ( hr )              )&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;    ::MessageBox ( 0, "",              "CoCreate failed",0) ;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;return S_OK              ;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;span style="font-size:100%;"&gt;  &lt;/span&gt;&lt;/blockquote&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;/dir&gt;&lt;dir&gt;&lt;p align="justify"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;This function creates an              instance of the inner object when the outer object first gets              initialized. Here we are using &lt;b&gt;CoCreateInstance( )&lt;/b&gt; to create the instance of the   CMouse coclass. The second parameter to &lt;b&gt;CoCreateInstance( )&lt;/b&gt; is the outer unknown of   CMouseTrails object. We do not know that              the current instance of the CMouse              coclass is the controlling object, or whether it too has been              aggregated. Hence we are using &lt;b&gt;GetControllingUnknown( )&lt;/b&gt; which will either return the              controlling outer IUnknown if it is              aggregated, or its own IUnknown if it is              not. The fourth parameter is the interface we are asking for, which              must be IUnknown when we are creating an              object as part of an aggregate.&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;/dir&gt;   &lt;ul&gt;&lt;span style="font-size:100%;"&gt;&lt;li&gt;   &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Add the following function to the                  ‘MouseTrails.h’ file.&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/span&gt;&lt;/ul&gt;&lt;dir&gt;  &lt;p&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;HRESULT FinalRelease(              )&lt;br /&gt;{&lt;br /&gt;      inner-&gt;Release( )              ;&lt;br /&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;/dir&gt;   &lt;ul&gt;&lt;span style="font-size:100%;"&gt;&lt;li&gt;   &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Add a   COM_INTERFACE_ENTRY_AGGREGATE( )                  macro for the IMouse interface to                  the com map.&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/span&gt;&lt;/ul&gt;  &lt;span style="font-size:100%;"&gt;  &lt;/span&gt;&lt;dir&gt;  &lt;p&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;COM_INTERFACE_ENTRY_AGGREGATE( IID_IMouse,              m_agg.p )&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p align="justify"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;This macro takes an interface              identifier for the interface that we are exposing and an IUnknown * for the inner object that              implements the interface. The macro itself hides the details that              handle the implementation of &lt;b&gt;QueryInterface(              )&lt;/b&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;/dir&gt;   &lt;ul&gt;&lt;span style="font-size:100%;"&gt;&lt;li&gt;   &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Update the file outer.idl file as shown                  below:&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/span&gt;&lt;/ul&gt;  &lt;dir&gt;  &lt;p&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;library              OUTERLib&lt;br /&gt;{&lt;br /&gt;       importlib("stdole32.tlb");&lt;br /&gt;       importlib("stdole2.tlb");&lt;br /&gt;       importlib("..\inner\inner.tlb");&lt;br /&gt;                    [&lt;br /&gt;                            uuid(CB45BCB0-8A4A-11BD-A251-E0EAC39E8615),&lt;br /&gt;                            helpstring("MouseTrails              Class")&lt;br /&gt;       ]&lt;br /&gt;coclass              MouseTrails&lt;br /&gt;{&lt;br /&gt;       [default]              interface IMouseTrails;&lt;br /&gt;                    interface IMouse ;&lt;br /&gt;};&lt;br /&gt;};&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;/dir&gt;  &lt;span style="font-size:100%;"&gt;&lt;b&gt;&lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Creating A Client&lt;/span&gt;&lt;/p&gt; &lt;/b&gt;&lt;/span&gt;&lt;p align="justify"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;The steps to create a COM              Client using MFC are as under:&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;ul&gt;&lt;span style="font-size:100%;"&gt;&lt;li&gt;   &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Create a dialog-based project using                  AppWizard (EXE).&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;   &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Add two edit boxes and three buttons to                  the dialog as shown in Figure 1.&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt; &lt;br /&gt;&lt;img src="http://www.kicit.com/freebies/com/aggr.gif" width="396" height="183" /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/span&gt;&lt;/ul&gt;  &lt;span style="font-size:100%;"&gt;&lt;span style="font-size:100%;"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-size:100%;"&gt;&lt;span style="font-size:100%;"&gt;    &lt;/span&gt;&lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-size:100%;"&gt;&lt;span style="font-size:100%;"&gt;      &lt;/span&gt;&lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-size:100%;"&gt;&lt;span style="font-size:100%;"&gt;        &lt;/span&gt;&lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-size:100%;"&gt;&lt;span style="font-size:100%;"&gt;          &lt;/span&gt;&lt;/span&gt;&lt;blockquote&gt;  &lt;p&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-size:100%;"&gt;      Figure 1.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;span style="font-size:100%;"&gt;&lt;span style="font-size:100%;"&gt;          &lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-size:100%;"&gt;&lt;span style="font-size:100%;"&gt;        &lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-size:100%;"&gt;&lt;span style="font-size:100%;"&gt;      &lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-size:100%;"&gt;&lt;span style="font-size:100%;"&gt;    &lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-size:100%;"&gt;&lt;span style="font-size:100%;"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;  &lt;span style="font-size:100%;"&gt;&lt;span style="font-size:100%;"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;ul&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-size:100%;"&gt;&lt;li&gt;   &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Add two variables m_trails and m_dctime of                  type integer for the two edit controls in the dialog box.&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;   &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Import the Type Libraries into the                  client. This is done by adding the following statements to the                  file ‘StdAfx.h’.&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/span&gt;&lt;/span&gt;&lt;/ul&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial Narrow;font-size:100%;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;p&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial Narrow;font-size:100%;"&gt;         &lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;#              import              "..\Outer\Outer.tlb"&lt;br /&gt;                     using namespace OUTERLib              ;&lt;br /&gt;         # import              "..\Inner\Inner.tlb"&lt;br /&gt;                    using namespace INNERLib ;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;   &lt;ul&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial Narrow;font-size:100%;"&gt;&lt;li&gt;   &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Add the regulation code in the &lt;b&gt;OnInitDialog( )&lt;/b&gt; function as shown                  below:&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/ul&gt;  &lt;span style="font-size:100%;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial Narrow;font-size:100%;"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;blockquote&gt;  &lt;p&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial Narrow;font-size:100%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;BOOL CContClientDlg::OnInitDialog(              )&lt;br /&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;span style="font-size:100%;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial Narrow;font-size:100%;"&gt;    &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;blockquote&gt;  &lt;p&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial Narrow;font-size:100%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;// AppWizard              generated code&lt;br /&gt;// TODO: Add extra              initialization here&lt;br /&gt;CLSID c              ;&lt;br /&gt;HRESULT h ;             &lt;br /&gt;CoInitialize ( NULL )              ;&lt;br /&gt;h = CLSIDFromProgID ( OLESTR (              "Outer.MouseTrails" ),&lt;/span&gt;&lt;span style="font-family:Arial Narrow;font-size:100%;"&gt; &lt;/span&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt; &amp;amp;c ) ;&lt;br /&gt;if ( FAILED ( h )              )&lt;br /&gt;MessageBox ( "CLSIDFromProgID Failed" ) ;&lt;br /&gt;h = CoCreateInstance ( c, NULL, CLSCTX_ALL, __uuidof ( IMouseTrails ), ( void ** ) &amp;amp;outer ) ;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial Narrow;font-size:100%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;if ( FAILED ( h ) )&lt;br /&gt;MessageBox ( "              Not able to create instance of an object ") ;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:100%;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial Narrow;font-size:100%;"&gt;      &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;p&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial Narrow;font-size:100%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;hr =              outer -&gt; QueryInterface ( __uuidof ( IMouse ), (void **)              &amp;amp;inner              );&lt;br /&gt;             if ( FAILED ( hr )              )&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:100%;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial Narrow;font-size:100%;"&gt;      &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-size:100%;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial Narrow;font-size:100%;"&gt;        &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;p&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial Narrow;font-size:100%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;MessageBox ( "Unable to query the inner interface" ) ;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:100%;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial Narrow;font-size:100%;"&gt;      &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;  &lt;p&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial Narrow;font-size:100%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;inner -&gt; SwapButtons = FALSE ;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial Narrow;font-size:100%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;return TRUE; // return TRUE unless you set              the focus to a control&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:100%;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial Narrow;font-size:100%;"&gt;    &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;  &lt;p&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial Narrow;font-size:100%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-size:100%;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial Narrow;font-size:100%;"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;   &lt;ul&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial Narrow;font-size:100%;"&gt;&lt;li&gt;   &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;From the class view tab add private                  variables outer, inner of types IMouseTrails * and IMouse * respectively to the   CClientDlg class.&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;   &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Use the COM Object. Now that we have                  obtained the interface pointer, the client application can call                  the methods of the COM server object as shown below:&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/ul&gt;  &lt;dir&gt;  &lt;p&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial Narrow;font-size:100%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;void CClientDlg::OnSwap( )&lt;br /&gt;{&lt;br /&gt;         // TODO: Add              your control notification handler code              he&lt;br /&gt;        inner -&gt; SwapButton( ) ;&lt;br /&gt;}&lt;/span&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial Narrow;font-size:100%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;void CClientDlg::OnMouseTrails( )             &lt;br /&gt;{&lt;br /&gt;     // TODO: Add your control              notification handler code here&lt;br /&gt;    UpdateData (              TRUE ) ;&lt;br /&gt;    inner -&gt; SetMouseTrails ( m_trails              ) ;&lt;br /&gt;}&lt;/span&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial Narrow;font-size:100%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;void CClientDlg::OnDoubleClick( )             &lt;br /&gt;{&lt;br /&gt;    // TODO: Add your control notification              handler code here&lt;br /&gt;   UpdateData ( TRUE )              ;&lt;br /&gt;   outer -&gt; Setdoubleclicktime ( m_dctime )              ;&lt;br /&gt;}&lt;/span&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;/dir&gt;   &lt;ul&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial Narrow;font-size:100%;"&gt;&lt;li&gt;   &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Uninitialize the COM library by the                  function &lt;b&gt;CoUninitialize( )&lt;/b&gt; at the                  end of &lt;b&gt;InitInstance( )&lt;/b&gt; function as                  shown below:&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/ul&gt;  &lt;dir&gt;  &lt;p&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial Narrow;font-size:100%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;BOOL CContClientApp::InitInstance(              )&lt;br /&gt;{&lt;br /&gt;     // wizard generate              code&lt;br /&gt;    CoUninitialize( ) ;&lt;br /&gt;                return FALSE;&lt;br /&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;/dir&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2252742141481837423-6079745045110381329?l=atlcomtutorial.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://atlcomtutorial.blogspot.com/feeds/6079745045110381329/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2252742141481837423&amp;postID=6079745045110381329' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2252742141481837423/posts/default/6079745045110381329'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2252742141481837423/posts/default/6079745045110381329'/><link rel='alternate' type='text/html' href='http://atlcomtutorial.blogspot.com/2008/08/reusability-in-com-ii-aggregation.html' title='Reusability In COM-II (Aggregation)'/><author><name>sandy</name><uri>http://www.blogger.com/profile/02503582209971047801</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2252742141481837423.post-2068352509075329856</id><published>2008-08-24T22:50:00.003-07:00</published><updated>2008-12-23T00:13:42.077-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ATL COM'/><title type='text'>Reusability In COM</title><content type='html'>&lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;COM promotes language-independent reuse. But so far we�ve only looked at clients using COM objects. Once the COM component is built it can be used by a client written in any language: VC, VB, Java, etc. Even scripting languages can use the component. But that�s only part of the reuse story. At times we may want to reuse an existing component while building another component. This way we can take advantage of the existing features of a component, and add to its functionality without being required to recompile the existing component. COM doesn�t support inheritance in the same sense as C++ does. This means we can�t derive one COM component from another the way we derive one C++ class from another.&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;COM offers two primary mechanisms for reusing existing components to build other components. These are &lt;i&gt;containment&lt;/i&gt; and &lt;i&gt;aggregation&lt;/i&gt;. In this episode we would look at the first of these mechanisms, i.e., containment.&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;In containment we can have one component as a member variable of another. The outer component makes use of the inner component, but does not directly expose the inner component to its clients. This is shown in the following figure.&lt;/span&gt;&lt;/p&gt; &lt;img src="http://www.kicit.com/freebies/com/reuse2.gif" width="204" height="120" /&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Figure 1.&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;The outer component can choose to use the inner component to implement some of its functionality. If the outer component decides to implement one or more of the interfaces of the inner component, it must provide a wrapper for every method in the inner component�s exposed interfaces. These wrapper methods can either call the inner component�s methods directly, or they can perform some additional tasks thereby extending the inner component�s interface.&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;The outer component manages the lifetime of the inner component. It typically creates the inner component with &lt;i&gt;CoCreateInstance( ) &lt;/i&gt;when it initializes itself (in the &lt;i&gt;FinalConstruct( )&lt;/i&gt; function), and releases the inner component�s interface pointer when it uninitializes itself (&lt;i&gt;FinalRelease( )&lt;/i&gt;). &lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Let us now understand containment with the help of some concrete example. Suppose we have a component that knows how to swap mouse buttons and set the time interval between two clicks of the mouse button. We can develop another component which uses this existing component and additionally also manage mouse trails. The existing component becomes the inner component. Given below is the procedure for building these components and a client that accesses the functionality of the inner component through the interface provided by the outer component. &lt;/span&gt;&lt;/p&gt; &lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;b&gt;&lt;p align="justify"&gt;Creating The Inner Component&lt;/p&gt; &lt;/b&gt;&lt;/span&gt;&lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;The process of creating components in ATL consists of three steps:&lt;/span&gt;&lt;/p&gt;  &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;b&gt;(a) Creating Module:&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;dir&gt;  &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;To create a module the Developer Studio provides an ATL COM AppWizard. Carry out the following steps:&lt;/span&gt;&lt;/p&gt;&lt;/dir&gt;   &lt;ul&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;li&gt;   &lt;p align="justify"&gt;Select �New� from the �File� menu. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;   &lt;p align="justify"&gt;Select �ATL COM AppWizard� as the project. Type �Inner� as the project name and click �OK� to continue. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;   &lt;p align="justify"&gt;Select type of module as �Dynamic Link Library�, click   �Finish�. &lt;/p&gt;&lt;/li&gt;&lt;/span&gt;&lt;/ul&gt; &lt;span style="font-family:Arial;font-size:85%;"&gt;  &lt;/span&gt;&lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;b&gt;(b) Adding Component To The Module&lt;/b&gt; &lt;/span&gt;&lt;/p&gt;&lt;dir&gt;  &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;To add component to the module we can use �ATL Object Wizard�. Carry out the following steps for adding a component using this wizard:&lt;/span&gt;&lt;/p&gt;&lt;/dir&gt;   &lt;ul&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;li&gt;   &lt;p align="justify"&gt;Select �Insert | New ATL Object� menu item. This would display the �ATL Object Wizard�  &lt;/p&gt;&lt;/li&gt;&lt;li&gt;   &lt;p align="justify"&gt;Select �Simple Object� from the various object categories and click on �Next�. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;   &lt;p align="justify"&gt;A �ATL Object Wizard Properties� dialog is displayed. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;   &lt;p align="justify"&gt;Enter the �Short Name� as �Mouse�. As soon as you do this all other edit controls would be filled automatically. Click on OK. &lt;/p&gt;&lt;/li&gt;&lt;/span&gt;&lt;/ul&gt; &lt;span style="font-family:Arial;font-size:85%;"&gt;  &lt;/span&gt;&lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;b&gt;(c) Adding Methods To The Component&lt;/b&gt; &lt;/span&gt;&lt;/p&gt;&lt;dir&gt;  &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;The component that has been added does not contain any functionality. To provide functionality we should add two methods named &lt;i&gt;SwapButton( )&lt;/i&gt; and &lt;i&gt;SetDoubleclicktime( )&lt;/i&gt; as indicated below.&lt;/span&gt;&lt;/p&gt;&lt;/dir&gt;   &lt;ul&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;li&gt;   &lt;p align="justify"&gt;Switch to class view tab. Select the interface �IMouse� and click the right mouse   button. From the menu that pops up, select �Add Method�. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;   &lt;p align="justify"&gt;In the �Add Method to Interface� dialog specify the method name as �SwapButton� and leave the parameters edit control empty. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;   &lt;p align="justify"&gt;Click on �OK�. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;   &lt;p align="justify"&gt;Adding the SwapButton( ) method creates a function definition in �Mouse.cpp� as shown below: &lt;/p&gt;&lt;/li&gt;&lt;/span&gt;&lt;/ul&gt; &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;STDMETHODIMP CMouse::SwapButton( )&lt;/span&gt;  &lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt; // TODO: Add your implementation code here return S_OK ;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;   &lt;ul&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;li&gt;   &lt;p align="justify"&gt;Add the following code to the &lt;i&gt;SwapButton( )&lt;/i&gt; method by double clicking on this method from the Class view tab:&lt;/p&gt;&lt;/li&gt;&lt;/span&gt;&lt;/ul&gt;  &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;mousestatus = !mousestatus ;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;SystemParametersInfo( SPI_SETMOUSEBUTTONSWAP,&lt;/span&gt; &lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;mousestatus,NULL,NULL) ;&lt;/span&gt; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;   &lt;ul&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;li&gt;   &lt;p align="justify"&gt;From the class view tab add a private variable &lt;i&gt;mousestatus&lt;/i&gt; of type BOOL to the &lt;i&gt;CMouse&lt;/i&gt; class. Initialize this variable to FALSE in the constructor of &lt;i&gt;CMouse&lt;/i&gt; class. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;   &lt;p align="justify"&gt;On similar lines add another method called &lt;i&gt;SetDoubleclicktime( )&lt;/i&gt;. Its code is given below:&lt;/p&gt;&lt;/li&gt;&lt;/span&gt;&lt;/span&gt;&lt;/ul&gt;  &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;STDMETHODIMP CMouse::SetDoubleclicktime ( long time )&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;AFX_MANAGE_STATE(AfxGetStaticModuleState( ) )&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;// TODO: Add your implementation code here&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;SystemParametersInfo(SPI_SETDOUBLECLICKTIME,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;time,NULL,NULL ) ;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;return S_OK ;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;b&gt;&lt;p align="justify"&gt;Creating The Outer Component&lt;/p&gt; &lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;The procedure for creating the outer component is same as that for creating the inner component, except for a few minor variations. First create a module called �Outer�. Insert a component called �MouseTrails� in it and then add three methods called &lt;i&gt;SwapButton( )&lt;/i&gt;, &lt;i&gt;SetDoubleclicktime( )&lt;/i&gt; and &lt;i&gt;SetMouseTrails( )&lt;/i&gt; to it.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;These methods are shown below:&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;STDMETHODIMP CMouseTrails::SwapButton()&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;AFX_MANAGE_STATE(AfxGetStaticModuleState())&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;inner -&gt; SwapButton() ;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;//TODO: Add your implementation code here&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;return S_OK;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;STDMETHODIMP CMouseTrails::Setdoubleclicktime(long time)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;AFX_MANAGE_STATE(AfxGetStaticModuleState( ) )&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;// TODO: Add your implementation code here&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;inner -&gt; SetDoubleclicktime ( time ) ;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;return S_OK ;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;STDMETHODIMP CMouseTrails::SetMouseTrails ( int trails )&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;AFX_MANAGE_STATE(AfxGetStaticModuleState( ) )&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;// TODO: Add your implementation code here&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;SystemParametersInfo ( SPI_SETMOUSETRAILS,&lt;/span&gt; &lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;trails,NULL,NULL ) ;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;return S_OK ;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;ul&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;li&gt;   &lt;p align="justify"&gt;From the class view tab add a private variable &lt;i&gt;inner&lt;/i&gt; of type &lt;i&gt;IMouse *&lt;/i&gt; to the &lt;i&gt;CMouseTrails&lt;/i&gt; class.&lt;br /&gt; &lt;/p&gt;&lt;/li&gt;&lt;li&gt;   &lt;p align="justify"&gt;In the �stdafx.h� file of the outer component add the following statements: &lt;/p&gt;&lt;/li&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/ul&gt;  &lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;" align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;#&lt;/span&gt;i&lt;span style="color:#0000ff;"&gt;mport "..\inner\inner.tlb"&lt;/span&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;" align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;using namespace INNERLib ;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;ul&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;li&gt;   &lt;p align="justify"&gt;Add the following two function to the �MouseTrails.h� file.&lt;/p&gt;&lt;/li&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/ul&gt;  &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;HRESULT FinalConstruct( )&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;HRESULT hr ;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;CLSID clsid ;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;CoInitialize ( NULL ) ;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;hr = CLSIDFromProgID ( OLESTR ( "inner.Mouse" ), &amp;amp;clsid ) ;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;if ( FAILED ( hr ) )&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 75px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;::MessageBox ( 0, "", "CLSIDFromProgID failed", 0 ) ;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;hr = CoCreateInstance ( clsid, NULL, CLSCTX_INPROC,&lt;/span&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;__uuidof ( IMouse ), ( void ** ) &amp;amp;inner ) ;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;if ( FAILED ( hr ) )&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 75px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;::MessageBox ( 0, "", "CoCreate failed",0) ;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;return S_OK ;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;HRESULT FinalRelease( )&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;inner-&gt;Release( ) ;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;b&gt;&lt;p align="justify"&gt;Creating A Client&lt;/p&gt; &lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;The steps to create a COM Client using MFC are as under:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;ul&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;li&gt;   &lt;p align="justify"&gt;Create a dialog-based project using AppWizard (EXE). &lt;/p&gt;&lt;/li&gt;&lt;li&gt;   &lt;p align="justify"&gt;Add two edit boxes and three buttons to the dialog as shown in Figure 2.&lt;/p&gt;&lt;/li&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/ul&gt;  &lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;p style="margin-left: 40px;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;img src="http://www.kicit.com/freebies/com/reuse1.gif" width="375" height="209" /&gt;&lt;br /&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;b&gt;Figure 2.&lt;/b&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;ul&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;li&gt;   &lt;p align="justify"&gt;Add two variables m_trails and m_dctime of type integer for the two edit controls in the dialog box. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;   &lt;p align="justify"&gt;Import the server�s Type Library into the client. This is done by adding the following two statement to the file �StdAfx.h�.&lt;/p&gt;&lt;/li&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/ul&gt;  &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;# import "..\Outer\Outer.tlb"&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;using namespace OUTERLib ;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;// Add the regulation code in the OnInitDialog( ) function as shown below:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;BOOL CContClientDlg::OnInitDialog( )&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;// AppWizard generated code&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;// TODO: Add extra initialization here&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;CLSID c ;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;HRESULT h ;&lt;/span&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;CoInitialize ( NULL ) ;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;h = CLSIDFromProgID ( OLESTR ( "Outer.MouseTrails" ), &amp;amp;c ) ;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;if ( FAILED ( h ) )&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 75px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;MessageBox ( "CLSIDFromProgID Failed" ) ;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;h = CoCreateInstance ( c, NULL, CLSCTX_ALL,&lt;/span&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;__uuidof ( IMouseTrails ), ( void ** ) &amp;amp;outer ) ;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;if ( FAILED ( h ) )&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 75px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;MessageBox ( " Not able to create instance of an object ") ;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;return TRUE; // return TRUE unless you set the focus to a control&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;   &lt;ul&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;li&gt;   &lt;p align="justify"&gt;From the class view tab add a private variable &lt;i&gt;outer&lt;/i&gt; of type &lt;i&gt;IMouseTrails *&lt;/i&gt; to the &lt;i&gt;CClientDlg&lt;/i&gt; class. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;   &lt;p align="justify"&gt;Use the COM Object. Now that we have obtained the interface pointer, the client application can call the methods of the COM server object as shown below: &lt;/p&gt;&lt;/li&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/ul&gt; &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;void CClientDlg::OnSwap( )&lt;/span&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;// TODO: Add your control notification handler code here&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;outer -&gt; SwapButton( ) ;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;void CClientDlg::OnMouseTrails( )&lt;/span&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;// TODO: Add your control notification handler code here&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;UpdateData ( TRUE ) ;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;outer -&gt; SetMouseTrails ( m_trails ) ;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;void CClientDlg::OnDoubleClick( )&lt;/span&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;// TODO: Add your control notification handler code here&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;UpdateData ( TRUE ) ;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;outer -&gt; Setdoubleclicktime ( m_dctime ) ;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;   &lt;ul&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;li&gt;   &lt;p align="justify"&gt;Uninitialize the COM library by the function &lt;i&gt;CoUninitialize( )&lt;/i&gt; at the end of &lt;i&gt;InitInstance( )&lt;/i&gt; function as shown below:&lt;/p&gt;&lt;/li&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/ul&gt;  &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;BOOL CContClientApp::InitInstance( )&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;// wizard generate code&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;CoUninitialize( ) ;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 60px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;color:#0000ff;"&gt;return FALSE;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-left: 45px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;With that we are through with the creation of the client. Now you can compile and execute the client and check out whether it is able to interact with the methods in the outer component.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2252742141481837423-2068352509075329856?l=atlcomtutorial.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://atlcomtutorial.blogspot.com/feeds/2068352509075329856/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2252742141481837423&amp;postID=2068352509075329856' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2252742141481837423/posts/default/2068352509075329856'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2252742141481837423/posts/default/2068352509075329856'/><link rel='alternate' type='text/html' href='http://atlcomtutorial.blogspot.com/2008/08/reusability-in-com.html' title='Reusability In COM'/><author><name>sandy</name><uri>http://www.blogger.com/profile/02503582209971047801</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2252742141481837423.post-8880643086081970945</id><published>2008-08-24T22:50:00.001-07:00</published><updated>2008-12-23T00:13:42.077-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ATL COM'/><title type='text'>Multiple Controls</title><content type='html'>&lt;p align="justify"&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;        This Article is used to bulid a                  full fledged ATL COM explorer Control. This article is divided                  into six steps.   &lt;/span&gt;&lt;/p&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;        Step 1: Creating the Project                 &lt;br /&gt;Step 2: Adding a Control to Project&lt;br /&gt;Step 3. Changing Control's Drawing Code&lt;br /&gt;Step 4: Adding a Methods to Control                 &lt;br /&gt;Step 5: Adding an Event to the Control&lt;br /&gt;Step 6: Adding a Property Page to Your                  Control   &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;        &lt;/span&gt;&lt;p align="justify"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;b&gt;         Creating the project &lt;/b&gt; :   &lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;              &lt;/span&gt;&lt;p align="justify"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt; First we have to create                  the initial ATL project using the ATL COM AppWizard. click New                  on the File menu, then choose the Projects tab. Select the ATL                  COM AppWizard. Type 'MultiControls' as the project name. In                  step2 check 'Support MFC' check box and click on Finish.                &lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;        Adding a Control :   &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;              &lt;/span&gt;&lt;p align="justify"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt; To add an object to an                  ATL project, you use the ATL Object Wizard. Click New ATL Object                  on the Insert menu, and the ATL Object Wizard appears. In the                  first ATL Object Wizard dialog box, select the category of                  object you want to add to your current ATL project. select the                  category as Controls on the left, then on the right select Full                  Control. Finally, click Next. A set of property pages is                  displayed that allows you to configure the control you are                  inserting into your project. Type "Explorer" as the                  short name. The other fields are automatically completed. Now                  check support for rich error information and connection points                  for your control. On the Attributes tab,Click the Support                  Connection Points check box. This will create support for an                  outgoing interface in the IDL file. Click on Miscellaneous tab,                  from Add Controls combo box select 'SysTreeView32' and in the                  others division check 'insertable' check button.You are finished                  selecting options for your control. Click OK. When you created                  your control, several code changes and additions were made.                  Changing Control's Code : Since we wish to display 'treectrl'                  (to display directory tree structure) on the left side of the                  control and 'listctrl' (to display the files present in the                  selected directory from the treectrl)on the right side. For                  initializing listctrl add the following code at the constructor               m_ctllist(_T("SysListView32"),this,2) where m_ctlist                  is the member variable that we have added. we have added code in                  &lt;em&gt;OnCreate( )&lt;/em&gt; to cretae the listctrl                  manually.   &lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;em&gt;m_ctllist&lt;/em&gt;.&lt;em&gt;Create(m_hWnd, rc,                  NULL,                  WS_BORDER|WS_CHILD|WS_VISIBLE|LVS_SMALLICON|LVS_SHOWSELALWAYS                  )&lt;/em&gt; ;&lt;/span&gt;   &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;        We have added &lt;em&gt;OnSize( )                  &lt;/em&gt;handler to resize both the controls.                  Important thing is we must add the following line   &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;        &lt;span style="color:#0000ff;"&gt;         ALT_MSG_MAP(2)&lt;/span&gt;   &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;        between   &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;        &lt;span style="color:#0000ff;"&gt;         BEGIN_MSG_MAP ( CExplorer )                 &lt;br /&gt;END_MSG_MAP( )&lt;/span&gt;   &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;        &lt;/span&gt;&lt;p align="justify"&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;        Adding properties to the                  control : A property 'format' is added to the controls                  interface,to change the formats of the files to be displayed at                  runtime.   &lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;        Adding Events to the                  control  :   &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;        &lt;/span&gt;&lt;p align="justify"&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;        Two event &lt;em&gt;GetPathFromTree( ) &lt;/em&gt;and &lt;i&gt;GetPathFromList( )&lt;/i&gt;&lt;em&gt; &lt;/em&gt;are added to the control . For                  knowing how to adding Events in ATL COM refer to article '                  Connection Points' in ATLCOM section of this website. &lt;i&gt;GetPathFromTree( )&lt;/i&gt; event is fired from                  &lt;em&gt;onselchanged( )&lt;/em&gt; handler to get the                  full directory path when we select a directory from the treectrl.                  &lt;em&gt;GetPathFromList( ) &lt;/em&gt;is                  fired from &lt;em&gt;onitemchanged( )&lt;/em&gt;                  handler to get the full path of the filename that was selected                  from the listctrl.   &lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;        &lt;b&gt;         Adding a property pages to the                  control :&lt;/b&gt;   &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;        &lt;/span&gt;&lt;p align="justify"&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;        Property pages are implemented                  as separate COM objects, which allow property pages to be shared                  if required. To add a property page to the control we can use                  the ATL Object Wizard.Start the ATL Object Wizard and select                  Controls as the category on the left. Select Property Page on                  the right, then click Next.we again get the dialog box allowing                  to enter the name of the new object. Call the object 'PropPage'                  and enter that name in the Short Name edit box. Notice that the                  Interface edit box is grayed out. This is because a property                  page doesn't need a custom interface. Click on the Strings tab                  to set the title of the property page. The title of the property                  page is the string that appears in the tab for that page. Type                  '&amp;amp;Format' as the title. Click OK and the property page                  object will be created. A dialog box template is added to the                  project resource for the property page. Now add the fields that                  we want to appear on the property page and write the appropriate                  code that we required in &lt;em&gt;Apply( )                  &lt;/em&gt;function . At Last Build the control,and test it usinig                  Activex Text Container.                &lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;           &lt;br /&gt;&lt;img src="http://www.kicit.com/freebies/com/explorer1.gif" width="444" height="401" /&gt;&lt;br /&gt;            &lt;b&gt;&lt;br /&gt;        Client&lt;/b&gt;                &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;        &lt;/span&gt;&lt;p align="justify"&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;        This program uses 'Explorer                  Control. Creation of these controls has been discussed in the                  previous article of the section 'ATL COM' in this same site. We                  have created the a dialog-based project called                  "ExplorerDemo'' using MFC AppWizard(exe). To use the                  ActiveX controls they have to be registered with the Windows                  registry. If you want to register these controls on your machine                  you will have to download "Explorer' control . Once                  registered these controls can be inserted in the dialog box.                  using the following procedure:   &lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;        &lt;/span&gt;&lt;p align="justify"&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;        From the 'Project' menu select                  'Add To Project' then select 'Components and Controls'. A dialog                  box will be popped up. Open 'Registered ActiveX Controls'                  folder. Search for the control to be inserted.(in our case                  'Explorer' control). Double click on both the controls to insert                  them in the project. The bitmap of these controls would now be                  visible in the 'Controls' toolbar of the dialog editor. Pick it                  and paste on the dialog box. You can see the preview of both in                  the dialog box. The dialog that we created is shown in Figure .                  Run the application to see the effect. Combo box is added to the                  dialog for changing the files format at runtime. A handler                  &lt;em&gt;OnSelchangeCombo1( ) &lt;/em&gt;is added to the                  dialog class which get called whenever we have changed the                  contents in the combo box. Inside this handler a call to &lt;em&gt;SetFormat( ) &lt;/em&gt;will update the control                  present on the the dialog with appropriate File Format. Using                  ClassWizard a handler corresponding to the event &lt;em&gt;GetPathFromList( ) &lt;/em&gt;is added and a                  inside the handler appropriate code is added such that when ever                  we clicked on the files present in the list control the file                  name with full path is displayed in an edit box.   &lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;&lt;br /&gt;&lt;img src="http://www.kicit.com/freebies/com/explorer2.gif" width="486" height="350" /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2252742141481837423-8880643086081970945?l=atlcomtutorial.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://atlcomtutorial.blogspot.com/feeds/8880643086081970945/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2252742141481837423&amp;postID=8880643086081970945' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2252742141481837423/posts/default/8880643086081970945'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2252742141481837423/posts/default/8880643086081970945'/><link rel='alternate' type='text/html' href='http://atlcomtutorial.blogspot.com/2008/08/multiple-controls.html' title='Multiple Controls'/><author><name>sandy</name><uri>http://www.blogger.com/profile/02503582209971047801</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2252742141481837423.post-5037773905981499304</id><published>2008-08-24T22:49:00.002-07:00</published><updated>2008-12-23T00:13:42.077-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ATL COM'/><title type='text'>Calendar ActiveX Control Using ATL</title><content type='html'>&lt;blockquote&gt;             &lt;p align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;             This Article is used to build a                  full fledged ATL COM calendar Control. This article is divided                  into six steps.&lt;/span&gt;               &lt;/p&gt;&lt;/blockquote&gt;             &lt;blockquote&gt;             &lt;p style="margin-top: 0pt; margin-bottom: 0pt;" align="justify"&gt;             &lt;span style="font-family:Arial;font-size:85%;"&gt;             Step 1: Creating the Project&lt;/span&gt;             &lt;/p&gt;&lt;p style="margin-top: 0pt; margin-bottom: 0pt;" align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Step 2: Adding a Control to                  Project&lt;/span&gt;&lt;/p&gt;             &lt;p style="margin-top: 0pt; margin-bottom: 0pt;" align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Step 3. Adding a Methods to                  Control&lt;/span&gt;&lt;/p&gt;             &lt;p style="margin-top: 0pt; margin-bottom: 0pt;" align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Step 4: Changing Control's                  Drawing Code&lt;/span&gt;&lt;/p&gt;             &lt;p style="margin-top: 0pt; margin-bottom: 0pt;" align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Step 5: Adding an Event to the                  Control&lt;/span&gt;&lt;/p&gt;             &lt;p style="margin-top: 0pt; margin-bottom: 0pt;" align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Step 6: Adding a Property Page                  to Your Control&lt;/span&gt;&lt;/p&gt;                &lt;/blockquote&gt;             &lt;blockquote&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;b&gt;Creating the project&lt;/b&gt;&lt;/span&gt;               &lt;/blockquote&gt;             &lt;blockquote&gt;             &lt;p style="margin-top: 0pt; margin-bottom: 0pt;" align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;             First we have to create the                  initial ATL project using the ATL COM AppWizard. Click New on                  the File menu, then choose the Projects tab.Select the ATL COM             AppWizard. Type 'CalendarServer' as the project name. In step2                  check 'Support MFC' check box and click on Finish.&lt;/span&gt;               &lt;/p&gt;&lt;/blockquote&gt;             &lt;blockquote&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;b&gt;Adding a                  Control&lt;/b&gt;&lt;/span&gt;               &lt;/blockquote&gt;             &lt;blockquote&gt;             &lt;p style="margin-top: 0pt; margin-bottom: 0pt;" align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;             To add an object to an ATL                  project, you use the ATL Object Wizard. Click New ATL Object on                  the Insert menu, and the ATL Object Wizard appears. In the first                  ATL Object Wizard dialog box, select the category of object you                  want to add to your current ATL project. select the category as                  Controls on the left, then on the right select Full Control.                  Finally, click Next. A set of property pages is displayed that                  allows you to configure the control you are inserting into your                  project. Type "Calendar" as the short name. The other                  fields are automatically completed. Now check support for rich                  error information and connection points for your control: On the                  Attributes tab,Click the Support Connection Points check box.                  This will create support for an outgoing interface in the IDL                  file.Click on the Stock Properties tab. You see a list box with                  all the possible stock properties you can enter. Scroll down the                  list, then double-click Fill Color to move it to the Supported                  list.You are finished selecting options for your control. Click                  OK. When you created your control, several code changes and                  additions were made.&lt;/span&gt;               &lt;/p&gt;&lt;/blockquote&gt;             &lt;blockquote&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;b&gt;Adding Methods to the                  control&lt;/b&gt;&lt;/span&gt;               &lt;/blockquote&gt;             &lt;blockquote&gt;             &lt;p style="margin-top: 0pt; margin-bottom: 0pt;" align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;             Add to Methods GetDate( ), and SetDate( ) to ICalendar interface and add the                  appropriate code to these methods.For knowing how to add methods                  in ATL COM refer to article 'Building Client and Servers' in                  ATLCOM section of this website.&lt;/span&gt;               &lt;/p&gt;&lt;/blockquote&gt;             &lt;blockquote&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;b&gt;Changing Control's                  Drawing Code&lt;/b&gt;&lt;/span&gt;               &lt;/blockquote&gt;             &lt;blockquote&gt;             &lt;p style="margin-top: 0pt; margin-bottom: 0pt;" align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;             By Default OnDraw( )                  handler is present in the CCalendar class. In this                  handler code is added to draw calendar.&lt;/span&gt;               &lt;/p&gt;&lt;/blockquote&gt;             &lt;blockquote&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;b&gt;Adding Events to the                  control&lt;/b&gt;&lt;/span&gt;               &lt;/blockquote&gt;             &lt;blockquote&gt;             &lt;p style="margin-top: 0pt; margin-bottom: 0pt;" align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;             Add an event NewDay( ) to the control .For knowing how to adding Events in ATL COM                  refer to article ' Connection Points' in ATLCOM section of this                  website and event is fired from OnLButtonDown( ) handler.&lt;/span&gt;               &lt;/p&gt;&lt;/blockquote&gt;             &lt;blockquote&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;b&gt;Adding a property pages                  to the control&lt;/b&gt;&lt;/span&gt;               &lt;/blockquote&gt;             &lt;blockquote&gt;             &lt;p style="margin-top: 0pt; margin-bottom: 0pt;" align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;             Property pages are implemented                  as separate COM objects, which allow property pages to be shared                  if required. To add a property page to the control we can use                  the ATL Object Wizard. Start the ATL Object Wizard and select                  Controls as the category on the left. Select Property Page on                  the right, then click Next.we again get the dialog box allowing                  to enter the name of the new object. Call the object PropPage                  and enter that name in the Short Name edit box. Notice that the                  Interface edit box is grayed out. This is because a property                  page doesn't need a custom interface. Click on the Strings tab                  to set the title of the property page. The title of the property                  page is the string that appears in the tab for that page. Type                  '&amp;amp;Date' as the title. Click OK and the property page object                  will be created. A dialog box template is added to the project                  resource for the property page.Now add the fields that we want                  to appear on the property page. and write the appropriate code                  that we required in Apply( ) function . At last Build                  the control,and test it usinig ActiveX Text Container.&lt;/span&gt;               &lt;/p&gt;&lt;/blockquote&gt; &lt;p style="margin-left: 40px;"&gt;&lt;br /&gt;&lt;img src="http://www.kicit.com/freebies/com/atlcalendar1.gif" width="452" height="411" /&gt;&lt;br /&gt;             &lt;/p&gt;&lt;blockquote&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;b&gt;Client&lt;/b&gt;&lt;/span&gt;               &lt;/blockquote&gt;             &lt;blockquote&gt;             &lt;p style="margin-top: 0pt; margin-bottom: 0pt;" align="justify"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;             This program uses 'Calendar'                  Control. Creation of these controls has been discussed in the                  previous articles of the section 'ATL COM' in this same site. We                  have created the a dialog-based project called                  "CalendarClient'' using MFC AppWizard(exe). To use the                  ActiveX controls they have to be registered with the Windows                  registry. If you want to &lt;/span&gt; register these controls on your machine                  you will have to download "CalendarServer' control . Once                  registered these controls can be inserted in the dialog box.                  using the following procedure: From the 'Project' menu select                  'Add To Project' then select 'Components and Controls'. A dialog                  box &lt;span style="font-family:Arial;font-size:85%;"&gt; will be popped up. Open 'Registered ActiveX Controls'                  folder. Search for the control to be inserted; in our case                  'Calendar' control Double click on both the controls to insert                  them in the project. The bitmaps of these controls would now be                  visible in the 'Controls' toolbar of the dialog editor. Pick it                  and paste on the dialog box. You can see the preview of both in                  the dialog box. The dialog that we created is shown in Figure.                  Run the application to see the effect. Two combo boxes are added                  to the dialog for months and years.a call to Initmonths(                  ) and Inityears( ) functions in OnInitDialog(                  ) handler fills the two comboboxe with months and years                  respectively.a handler OnCombosChanged( ) is added to                  the dialog class which get called whenever we have changed the                  contents in the combo box. Inside this handler a call to GetDate( ) and             SetDate( ) methods will update                  the calendar control present on the the dialog with appropriate                  date. Using ClassWizard a handler corresponding to the event             NewDay( ) is added and a inside the handler appropriate                  code is added such that when ever we clicked on the calendar                  control the date and day of the grid clicked get displayed in a                  message box .&lt;/span&gt;               &lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;img src="http://www.kicit.com/freebies/com/atlcalendar2.gif" width="362" height="244" /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2252742141481837423-5037773905981499304?l=atlcomtutorial.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://atlcomtutorial.blogspot.com/feeds/5037773905981499304/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2252742141481837423&amp;postID=5037773905981499304' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2252742141481837423/posts/default/5037773905981499304'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2252742141481837423/posts/default/5037773905981499304'/><link rel='alternate' type='text/html' href='http://atlcomtutorial.blogspot.com/2008/08/calendar-activex-control-using-atl.html' title='Calendar ActiveX Control Using ATL'/><author><name>sandy</name><uri>http://www.blogger.com/profile/02503582209971047801</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2252742141481837423.post-241698247294954993</id><published>2008-08-24T22:49:00.001-07:00</published><updated>2008-12-23T00:13:42.077-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ATL COM'/><title type='text'>Connection Points</title><content type='html'>&lt;span style="font-family:arial;font-size:85%;"&gt;              &lt;strong&gt;Adding an Event to an                  ATL controls&lt;/strong&gt;                                 &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt; &lt;/span&gt;&lt;p align="justify"&gt; &lt;span style="font-family:arial;font-size:85%;"&gt; Now we will add a and a event                  to your ATL control. You will fire the &lt;em&gt;ClickFirstpane(                  )&lt;/em&gt; event if the user clicks within the first pane of the                  control and fire &lt;em&gt;ClickSecondPane( )&lt;/em&gt; if the user clicks                  within second pane. Building a component in ATL is a four-step                  process:    &lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt; &lt;/span&gt;&lt;p align="justify"&gt; &lt;span style="font-family:arial;font-size:85%;"&gt; (a) Creating a module&lt;br /&gt;(b)                  Adding a component to the module&lt;br /&gt;(c) Adding methods to the                  component&lt;br /&gt;(d) Adding properties to the component.    &lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt; &lt;/span&gt;&lt;p align="justify"&gt; &lt;span style="font-family:arial;font-size:85%;"&gt; We would create a module                  (usually a DLL) called 'conpoint'. Then we will create a                  component called &lt;em&gt;mycon&lt;/em&gt; within this server. Let us carry                  out these steps now.    &lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;strong&gt;Creation Of Module                  &lt;/strong&gt;    &lt;/span&gt;&lt;/blockquote&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt; &lt;/span&gt;&lt;p align="justify"&gt; &lt;span style="font-family:arial;font-size:85%;"&gt; To create a module the                  Developer Studio provides an ATL COM AppWizard. This is the                  easiest of jobs. Carry out the following steps:    &lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt; &lt;/span&gt;&lt;p align="justify"&gt; &lt;span style="font-family:arial;font-size:85%;"&gt; (a) Select ‘New’                  from the ‘File menu. From the dialog that pops up select                  ‘ATL COM AppWizard’ as the project. Type                  ‘conpoint’ as the project name and click                  ‘OK’ to continue.&lt;br /&gt;(b) Select type of module as                  ‘Dynamic Link Library’ and click                  ‘Finish’.&lt;br /&gt;(c) Now a ‘New Project                  Information’ dialog is displayed which lists the name of                  files that the wizard would create. Click on ‘OK’.                  Now that the module stands created let us add a component to it.                     &lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;strong&gt;Adding Component To The                  Module &lt;/strong&gt;    &lt;/span&gt;&lt;/blockquote&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt; &lt;/span&gt;&lt;p align="justify"&gt; &lt;span style="font-family:arial;font-size:85%;"&gt; To add component to the module                  we can use ‘ATL Object Wizard’. Carry out the                  following steps for adding the component named                  ‘Calculator’ using this wizard:    &lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt; &lt;/span&gt;&lt;p align="justify"&gt; &lt;span style="font-family:arial;font-size:85%;"&gt; (a) Select ‘Insert | New                  ATL Object’ menu item. This would display the ‘ATL                  Object Wizard’ dialog.Select 'controls' from the                  categories List box and Select ‘Full control’ from                  the various object categories and click on ‘Next’.                 &lt;br /&gt;(b) An ‘ATL Object Wizard Properties’ dialog is                  displayed&lt;br /&gt;(c) The property sheet contains two tabs-Names and                  Attributes.    &lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt; &lt;/span&gt;&lt;p align="justify"&gt; &lt;span style="font-family:arial;font-size:85%;"&gt; The Names tab is divided into                  two sections. The first section displays the ‘C++                  names’ and the second section the ‘COM names’.                  Enter the ‘Short Name’ as &lt;em&gt;mycon&lt;/em&gt;. As soon as                  you do this all other edit controls would be filled                  automatically . The names filled under the edit controls of                  ‘C++ names’ indicate that the class &lt;em&gt;Cmycon&lt;/em&gt;                  will implement the object mycon in the files                  ‘mycon.h’ and ‘mycon.cpp’.The names                  filled under the edit controls of ‘COM names’                  indicate that the &lt;em&gt;CoClass&lt;/em&gt; name (component class)                  remains the same as the short name. The Interface name will be                  &lt;em&gt;Imycon&lt;/em&gt;. The type is a description for the class. The                  ProgID will be 'compoint.mycon' and from the attributes tab, you selected the                  Support Connection Points check box. This created the                  &lt;em&gt;ImyconEvents&lt;/em&gt; interface in your .idl file. Note that the                  interface name starts with an underscore. This is a convention                  to indicate that the interface is an internal interface. Thus,                  programs that allow you to browse COM objects can choose not to                  display the interface to the user. Also notice in the .idl file                  that Support Connection Points added a line to indicate that                  ImyconEvents is the default source interface. The source                  attribute indicates that the control is the source of the                  notifications, so it will call this interface on the container.                  When the ‘OK’ button is clicked, the class                  &lt;em&gt;Cmycon&lt;/em&gt; and the interface &lt;em&gt;Imycon&lt;/em&gt; are created.                  They can be viewed from the class view tab. Now you should add                  the &lt;em&gt;ClickFirstPane( )&lt;/em&gt; and &lt;em&gt;ClickSecondPane( )                  &lt;/em&gt;methods to the &lt;em&gt;ImyconEvents&lt;/em&gt; interface: Right click                  on &lt;em&gt;ImyconEvents&lt;/em&gt; in ClassView and selecting Add Method                  from the popup menu. From the Add Method dialog box, select a                  Return Type of &lt;em&gt;void&lt;/em&gt;. Type &lt;em&gt;ClickFirstPane&lt;/em&gt; in                  the Method Name box. Enter [in] long x, [in] long y in the                  Parameters box. Click OK. Check the '.idl' file to see that the                  code was added as a method to the &lt;em&gt;ImyconEvents&lt;/em&gt;   dispinterface. Then use the same procedure to define a                  &lt;em&gt;ClickSecondPane&lt;/em&gt; method with the same parameters and                  return type. The &lt;em&gt;ImyconEvents&lt;/em&gt; dispinterface in your .idl file should now look like this:    &lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt; &lt;/span&gt;&lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;  dispinterface _ImyconEvents                 &lt;br /&gt;{&lt;/span&gt;    &lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt; &lt;/span&gt;&lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;  properties:&lt;br /&gt;methods:                     &lt;br /&gt;[id(1), helpstring("method ClickFirstPane")]                      void ClickFirstPane(int x,int y);&lt;br /&gt;[id(2),                      helpstring("method ClickSecondPane")] void                      ClickSecondPane(int x, int y);&lt;/span&gt;    &lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;/blockquote&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt; &lt;/span&gt;&lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;  } ;&lt;/span&gt;    &lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt; &lt;/span&gt;&lt;p align="justify"&gt; &lt;span style="font-family:arial;font-size:85%;"&gt; The &lt;em&gt;ClickFirstPane( )&lt;/em&gt;                  and &lt;em&gt;ClickSeconePane( )&lt;/em&gt; methods that take the x and y                  coordinates of the clicked point as parameters.Now generate your                  type library. To do this you can either rebuild your project or                  right-click the '.idl' file in FileView and click Compile                  'conpiont.idl'. This will create the mycon.tlb file, which is                  your type library. Next, implement a connection point interface                  and a connection point container interface for your control. (In                  COM, events are implemented through the mechanism of connection                  points. To receive events from a COM object, a container                  establishes an advisory connection to the connection point that                  the COM object implements. Since a COM object can have multiple                  connection points, the COM object also implements a connection                  point container interface. Through this interface, the container                  can determine which connection points are supported.) The                  interface that implements a connection point is called                  &lt;em&gt;IConnectionPoint&lt;/em&gt; and the interface that implements a                  connection point container is called                  &lt;em&gt;IConnectionPointContainer&lt;/em&gt;. To help implement                  &lt;em&gt;IConnectionPoint&lt;/em&gt;, use ClassView to access a connection                  point wizard. This wizard generates the                  &lt;em&gt;IConnectionPoint&lt;/em&gt; interface by reading your type library                  and implementing a function for each event that can be fired. To                  run the wizard, follow these steps: Go to ClassView (on the View                  menu, click Workspace to see ClassView). Right click on your                  control's implementation class, in this case &lt;em&gt;Cmycon&lt;/em&gt;. In                  the shortcut menu, select Implement Connection Point. Select                  &lt;em&gt;_ImyconEvents &lt;/em&gt;from the Interfaces list then click OK                  and a proxy class for the connection point will be generated, in                  this case, &lt;em&gt;CProxy_ImyconEvents&lt;/em&gt;. This is shown in below                  figure.    &lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;&lt;br /&gt;&lt;img src="http://www.kicit.com/freebies/com/conpoints1.gif" width="425" height="337" /&gt;&lt;br /&gt;  &lt;/span&gt;&lt;/blockquote&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt; &lt;/span&gt;&lt;p align="justify"&gt; &lt;span style="font-family:arial;font-size:85%;"&gt; If you look at the generated                  'conpointCP.h' file in FileView, you see it has a class called                  &lt;em&gt;CProxy_ImyconEvents&lt;/em&gt; that derives from                  &lt;em&gt;IConnectionPointImpl&lt;/em&gt;. 'conpointCP.h' also defines the                  two methods &lt;em&gt;Fire_ClickFirstPane( )&lt;/em&gt; and                  &lt;em&gt;Fire_ClickSecondPane( )&lt;/em&gt;, which take the two coordinate                  parameters. These are the methods you call when you want to fire                  an event from your control. The wizard also added the                  &lt;em&gt;CProxy_ImyconEvents&lt;/em&gt; and                  &lt;em&gt;IConnectionPointContainerImpl&lt;/em&gt; to your control's                  multiple inheritance list. The wizard also exposed                  &lt;em&gt;IConnectionPointContainer&lt;/em&gt; for you by adding appropriate                  entries to the COM map. You are finished implementing the code                  to support events. Now, add some code to fire the events at the                  appropriate moment. Remember, you are going to fire a                  &lt;em&gt;ClickFirstPane&lt;/em&gt; or &lt;em&gt;ClickSecondPane&lt;/em&gt; event when                  the user clicks the left mouse button in the control. To find                  out when the user clicks the button, first add a handler for the                  WM_LBUTTONDOWN message. In ClassView, right click on the                  &lt;em&gt;Cmycon&lt;/em&gt; class and select 'Add Windows Message Handler'                  from the shortcut menu. Then select WM_LBUTTONDOWN from the list                  on the left and click the 'Add Handler' button. Click OK. Next,                  add new code to the &lt;em&gt;OnLButtonDown( )&lt;/em&gt; function in                  mycon.h (deleting any code placed by the wizard) so that                  &lt;em&gt;OnLButtonDown( )&lt;/em&gt; now looks like this:    &lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt; &lt;/span&gt;&lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;  LRESULT OnLButtonDown ( UINT                  uMsg, WPARAM wParam, LPARAM lParam, BOOL&amp;amp; bHandled )&lt;br /&gt;{&lt;/span&gt;  &lt;/span&gt;&lt;/p&gt;&lt;p style="margin-left: 25px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;// TODO : Add Code for message                  handler. Call DefWindowProc if necessary.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-family:arial;font-size:85%;"&gt; &lt;/span&gt;&lt;p style="margin-left: 25px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;POINT pt ;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-family:arial;font-size:85%;"&gt; &lt;/span&gt;&lt;p style="margin-left: 25px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;pt.x = LOWORD ( lParam ) ;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-family:arial;font-size:85%;"&gt; &lt;/span&gt;&lt;p style="margin-left: 25px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;pt.y = HIWORD ( lParam ) ;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-family:arial;font-size:85%;"&gt; &lt;/span&gt;&lt;p style="margin-left: 25px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;if ( PtInRect(&amp;amp;r1,pt ) )&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-family:arial;font-size:85%;"&gt; &lt;/span&gt;&lt;p style="margin-left: 25px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;Fire_ClickFirstPane(pt.x,pt.y) ;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-family:arial;font-size:85%;"&gt; &lt;/span&gt;&lt;p style="margin-left: 25px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;else&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-family:arial;font-size:85%;"&gt; &lt;/span&gt;&lt;p style="margin-left: 25px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;Fire_ClickSecondPane(pt.x,pt.y) ;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-family:arial;font-size:85%;"&gt; &lt;/span&gt;&lt;p style="margin-left: 25px; margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;return 0;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-family:arial;font-size:85%;"&gt; &lt;/span&gt;&lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;               &lt;/span&gt;&lt;/blockquote&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt; &lt;/span&gt;&lt;p align="justify"&gt; &lt;span style="font-family:arial;font-size:85%;"&gt; Since you have already                  calculated the points of the two panes in the &lt;em&gt;OnDraw( )&lt;/em&gt;                  function, use them in &lt;em&gt;OnLButtonDown( )&lt;/em&gt;, use the                  &lt;em&gt;PtInRect( )&lt;/em&gt; API function to determine whether the                  clicked point is in first pane or not. Now try out your events.                  Build the control and start ActiveX Control Test Container .                  This time, view the event log window. To route events to the                  output window, select Logging from the Options menu and select                  Log to output window. Now insert the control and try clicking in                  the window. Notice that &lt;em&gt;ClickFirstPane( )&lt;/em&gt; is fired if                  you click within the first pane and &lt;em&gt;ClickSecondPane( )&lt;/em&gt;                  is fired when you click in second panet.    &lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;br /&gt;&lt;img src="http://www.kicit.com/freebies/com/conpoints2.gif" width="407" height="411" /&gt; &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2252742141481837423-241698247294954993?l=atlcomtutorial.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://atlcomtutorial.blogspot.com/feeds/241698247294954993/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2252742141481837423&amp;postID=241698247294954993' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2252742141481837423/posts/default/241698247294954993'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2252742141481837423/posts/default/241698247294954993'/><link rel='alternate' type='text/html' href='http://atlcomtutorial.blogspot.com/2008/08/connection-points.html' title='Connection Points'/><author><name>sandy</name><uri>http://www.blogger.com/profile/02503582209971047801</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2252742141481837423.post-4924702079148005263</id><published>2008-08-24T22:48:00.000-07:00</published><updated>2008-12-23T00:13:42.077-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ATL COM'/><title type='text'>Building Server And Client</title><content type='html'>&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;strong&gt;Creating the                  Server&lt;/strong&gt;  &lt;br /&gt;&lt;br /&gt;Building a component in ATL is a                  four-step process:               &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;(a) Creating a module&lt;br /&gt;(b) Adding a component to the module&lt;br /&gt;(c) Adding methods to the component&lt;br /&gt;(d) Adding properties to the component We                  would create a module&lt;br /&gt;    (usually a DLL) called &lt;em&gt;CalcServer&lt;/em&gt;.                &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;Then we will create a component                  called Calculator within this server. Then we would add 15                  methods and one property to it. Let us carry out these steps                  now.   &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;strong&gt;Creation Of Module                  &lt;/strong&gt;  &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;To create a module the Developer                  Studio provides an ATL COM AppWizard. This is the easiest of                  jobs. Carry out the following steps:   &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;(a) Select ‘New’                  from the ‘File menu. From the dialog that pops up select                  ‘ATL COM AppWizard’ as the project. Type                  ‘CalcServer’ as the project name and click                  ‘OK’ to continue.&lt;br /&gt;(b) Select                  type of module as ‘Dynamic Link Library’ and click ‘Finish’.&lt;br /&gt;(c) Now a                  ‘New Project Information’ dialog is displayed which                  lists the name of files that the wizard would create. Click on                  ‘OK’.                &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;Now that the module stands                  created let us add a component to it.   &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;strong&gt;Adding Component To The Module &lt;/strong&gt;  &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;To add component to the module                  we can use ‘ATL Object Wizard’. Carry out the                  following steps for adding the component named                  ‘Calculator’ using this wizard:   &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;(a) Select ‘Insert | New                  ATL Object’ menu item. This would display the ‘ATL                  Object Wizard’ dialog. Select ‘Simple Object’                  from the various object categories and click on                  ‘Next’.&lt;br /&gt;(b) A ‘ATL                  Object Wizard Properties’ dialog is displayed.&lt;br /&gt;(c) The property sheet contains two                  tabs-Names and Attributes.   &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;The Names tab is divided into                  two sections. The first section displays the ‘C++                  names’ and the second section the ‘COM names’.                  Enter the ‘Short Name’ as 'Calculator'. As soon as                  you do this all other edit controls would be filled                  automatically. The names filled under the edit controls of                  ‘C++ names’ indicate that the class                  &lt;em&gt;CCalculator&lt;/em&gt; will implement the object Calculator in                  the files ‘Calculator.h’ and                  ‘Calculator.cpp’. The names filled under the edit                  controls of ‘COM names’ indicate that the CoClass                  name (component class) remains the same as the short name. The                  Interface name will be &lt;em&gt;ICalculator&lt;/em&gt;.                  The type is a description for the class. The ProgID will                  be.. When the ‘OK’ button is                  clicked, the class &lt;em&gt;CCalculator&lt;/em&gt; and                  the interface                  &lt;em&gt;ICalculator&lt;/em&gt; are                  created. They can be viewed from the class view tab.   &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;strong&gt;Adding Methods To The Component &lt;/strong&gt;  &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;The component that has been                  added does not contain any functionality. To provide                  functionality we should add several methods to it. Here we would                  show addition of one method. On similar lines you should add the                  rest.   &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;p align="justify"&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;(a) Switch to class view tab. Select the interface &lt;em&gt;ICalculator&lt;/em&gt;                  and click the right mouse button. From the menu that pops up select ‘Add Method’. Note that the interface &lt;em&gt;ICalculator&lt;/em&gt; appears twice in the class                  view. Any one can be used to add methods.&lt;br /&gt;(b) In the ‘Add Method to Interface’ dialog                  specify the method name as Add and parameters as [in] double n1,                  [in] double n2, [out, retval] double *n3. Click on                  ‘OK’. Here [in] specifies the value to be passed to                  the method and [out, retval] specifies the return value.&lt;br /&gt;(c) Follow a similar procedure for adding                  the following methods:                &lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;p style="margin-left: 20px;" align="justify"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt; Subtract ( [in]double n1,                  [in]double n2, [out, retval] double *n3 ) ;&lt;br /&gt;Multiply ( [in] double n1, [in]double n2, [out, retval]                  double *n3 ) ;&lt;br /&gt;XpowY ( [in] double n1,                  [in]double n2, [out, retval] double *n3 ) ;                 &lt;br /&gt;Divide ( [in] double n1, [in]double n2, [out, retval]                  double *n3 ) ;&lt;br /&gt;onebyx ( [in] double n1,                  [out, retval] double *n2 ) ;&lt;br /&gt;Percent (                  [in] double n1, [in]double n2, [out, retval] double *n3 ) ;&lt;br /&gt;sqrroot ( [in]double n1, [out, retval]                  double * n2 ) ;&lt;br /&gt;Sineval ( [in]double                  n1,[out, retval]double *n2 ) ;                 &lt;br /&gt;CosVal (                  [in]double n1,[out, retval]double *n2 ) ;                 &lt;br /&gt;tanvalue ( [in]double n1,[out, retval] double * n2 ) ;                 &lt;br /&gt;Xpow3 ( [in]double n1, [out, retval]double                  *n2 ) ;&lt;br /&gt;Xpow2 ( [in]double n1, [out,                  retval]double *n2 ) ;&lt;br /&gt;Nfact ( [in]int                  n1,[out, retval]double *n2 ) ;&lt;br /&gt;Log10 (                  [in]double n1, [out, retval]double *n2 ) ;&lt;/span&gt;   &lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;Adding the Add method creates a                  function definition in ‘Calculator.cpp’ as shown                  below.   &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt; STDMETHODIMP CCalculator::Add (                  double n1, double n2, double *n3 )&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt; // TODO: Add your                      implementation code here&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;return S_OK                      ;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;/blockquote&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;              &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;We can add the following line to                  the &lt;em&gt;Add( ) &lt;/em&gt;method by double                  clicking it from the Class view tab: &lt;/span&gt;&lt;p&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;*n3                  = n1 + n2 ;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;On similar lines complete the                  definitions of the other 14 methods.   &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;strong&gt;Adding Properties To The Component &lt;/strong&gt;  &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;A property helps expose a member                  variable of the server. The client can use this variable. For                  every property that we expose there are two member functions in                  the server: one that puts the value in the variable and another                  that gets the value of the variable. Carry out the following                  steps to add the property.&lt;br /&gt;(a) Switch to                  class view tab. Select the interface &lt;em&gt;ICalculator&lt;/em&gt; and click the right mouse button. From the                  menu that pops up select ‘Add Properties’.&lt;br /&gt;(b) In the ‘Add Property to                  Interface’ dialog specify the property type as BSTR and                  property name as Memval. Check the ‘Get Function’                  and the ‘Put function’ from the dialog and click on                  OK.   &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;This adds the following methods                  to the server in ‘Calculator.cpp’ as shown below:                &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt; STDMETHODIMP CCaluculator::get_Memval ( double *pVal )&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt; AFX_MANAGE_STATE(AfxGetStaticModuleState( ) )&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;// TODO: Add your implementation code                      here&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;return S_OK;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;                  &lt;/span&gt;&lt;/blockquote&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt; }&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;                  &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt; STDMETHODIMP CCaluculator::put_Memval ( double newVal )&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;AFX_MANAGE_STATE ( AfxGetStaticModuleState( ) )&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;// TODO: Add your implementation code                      here&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;return S_OK ;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;                  &lt;/span&gt;&lt;/blockquote&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt; }&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;Now add the following line to                  the &lt;em&gt;get_Memval( )&lt;/em&gt; method:&lt;br /&gt;&lt;span style="color:#0000ff;"&gt;&lt;br /&gt;*pVal = memory ;&lt;/span&gt;   &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;Similarly add the following line                  to the &lt;em&gt;put_Memval( ) &lt;/em&gt;method.&lt;br /&gt;&lt;span style="color:#0000ff;"&gt;&lt;br /&gt;memory = newVal ;&lt;/span&gt;                &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;Note that the variable memory                  must be added as a private member variable of the                  &lt;em&gt;CCalculator&lt;/em&gt; class using ClassWizard.                  Now if we build the project, a DLL file would be created                  containing the component having fifteen methods and one                  property. Now what remains to be done is building a client that                  would use these methods and property.   &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;strong&gt;Creating the Client                  &lt;/strong&gt;  &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;After knowing how to create a                  component (server) using ATL COM. now we would see how to                  develop a client that makes use of this component. We would                  develop the client as a simple dialog-based application. But                  before we do that let me state a few facts about the server that                  we developed while building the server. While building the                  component we first created a module called &lt;em&gt;CalcServerr&lt;/em&gt;. Then we created a component called                  Calculator within this server. Lastly we added methods and a                  property to it.   &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;strong&gt;Creating A COM Client                  &lt;/strong&gt;  &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;The steps to create a COM Client                  using MFC are:   &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;strong&gt;Step                  1: &lt;/strong&gt;Create a dialog-based project using AppWizard (EXE).                  The dialog acts as an interface between the client can feed the                  numbers that interface with the server through the client.                &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;strong&gt;Step                  2:&lt;/strong&gt; Add buttons to the dialog.   &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;strong&gt;Step                  3:&lt;/strong&gt; Import the server’s Type Library into the                  client. This is done by adding the following two statement to                  the file ‘StdAfx.h’. # import                  “..\CalcServer\CalcServer.tlb” using namespace                  CALCSERVERLib ; When we compile the client project # import                  keyword creates the header for the wrapper class in a file with               .tlh extension and the implementation in another file with                  extension .til. These files are present in the Debug directory                  of the client’s project workspace. The name of the wrapper                  class is the server workspace name plus the keyword Lib. In our                  case it turns out to be CALCSERVERLib. The wrapper class                  contains information about the server that is used while                  accessing the methods defined in the server from the client.                  This wrapper class hides the details of reference counting and                  permits us to throw errors.   &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;strong&gt;Step                  4:                  &lt;/strong&gt;Initialize the COM Library so that the application                  can call COM functions. The client can interact with the server                  through the COM Runtime Library. To initialize the COM Library,                  call &lt;em&gt;CoInitialize( )&lt;/em&gt; function from &lt;em&gt;InitInstance( )&lt;/em&gt; as shown below:&lt;br /&gt;&lt;span style="color:#0000ff;"&gt;CoInitialize (NULL ) ;&lt;/span&gt;   &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;strong&gt;Step                  5:                  &lt;/strong&gt;Retrieve the CLSID of the server to be able to                  instantiate the server. As it is difficult to remember the CLSID                  it can be retrieved using the ProgID through the function                  &lt;em&gt;CLSIDFromProgID( )&lt;/em&gt; as shown below:                &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt; BOOL                  CCalcClientDlg::OnInitDialog( )&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt; // AppWizard generated code&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;// TODO: Add extra initialization                      here&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;CoInitialize ( NULL ) ;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;CLSID clsid ;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;HRESULT hr ;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;hr =                      CLSIDFromProgID( OLESTR  ( "CalcServer.Caluculator" ), &amp;amp;clsid ) ;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt; if ( FAILED ( hr ) )&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;MessageBox ( "Unable to access                      server" ) ;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;                  &lt;/span&gt;&lt;/blockquote&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;                &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt; }&lt;/span&gt;   &lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;Here &lt;em&gt;OLESTR( )&lt;/em&gt; function has been called to converts the                  character string to the ProgID format.   &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;strong&gt;Step                  6: &lt;/strong&gt;Using the CLSID of the component create an instance                  of the COM Server component. The &lt;em&gt;CoCreateInstance( ) &lt;/em&gt;function is used for this purpose                  as shown below:   &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt; BOOL                  CCalcClientDlg::OnInitDialog( )&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;              &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt; // AppWizard generated code&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;// TODO: Add extra initialization                      here&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;// calls to CoInitialize and                      CLSIDFromProgID( )&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;hr =                      CoCreateInstance ( clsid, NULL, CLSCTX_ALL, __uuidof (                      ICaluculator ), ( void ** ) &amp;amp;p ) ;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt; if ( FAILED ( hr ) )&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;MessageBox ( "cocreate failed"                      ) ;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;              &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt; }&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;Call to &lt;em&gt;CoCreateInstance( )&lt;/em&gt; creates an instance of the                  component IMyMath and returns the interface address in the                  pointer math. The parameter CLSCTX_INPROC_SERVER indicates that                  our server is a DLL. The                  &lt;em&gt;__uuidof(                  )&lt;/em&gt; function has been used to obtain the id of the interface.                    &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;strong&gt;Step                  7: &lt;/strong&gt;Use the COM Object. Now that we have obtained the                  interface pointer, the client application can call the methods                  of the COM server object as shown below:   &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt; void CCalclientDlg::OnEqual( )&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt; if ( m_oper == ' ' )&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;return ;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt; double num3 ;&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;GetDlgItemText ( IDC_DISPLAY, m_str ) ;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;m_num2 = atof ( m_str ) ;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt; switch ( m_oper )&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;                  &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;                &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt; case '+' :&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;num3 = p -&gt; Add ( m_num1, m_num2                          ) ;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;break ;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt; case '-' :&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;num3 = p -&gt; Subtract ( m_num1,                          m_num2 ) ;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;break ;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt; case '*' :&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;num3 = p -&gt; Multiply ( m_num1,                          m_num2 ) ;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;break ;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt; case '^' :&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;num3 = p -&gt; XpowY ( m_num1,                          m_num2 ) ;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;break ;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt; case '/' :&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;if ( m_num2 == 0 )&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt; m_over = true ;&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;m_decipoint = false ;SetDlgItemText ( IDC_DISPLAY,                          "Cannot divide by zero." ) ;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;return ;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt; }&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;else&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;num3 = p -&gt; Divide                          ( m_num1, m_num2 ) ;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;                    &lt;/span&gt;&lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;}&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt; m_str.Format (                      "%.8g", num3 ) ;&lt;/span&gt;   &lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt; if ( m_str == "0"                      )&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;m_str = "0." ;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt; m_over = true ;&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;m_decipoint = false ;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;m_oper = ' ' ;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;SetDlgItemText (                      IDC_DISPLAY, m_str ) ;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;              &lt;/span&gt;&lt;/blockquote&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt; }&lt;/span&gt;   &lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;Note that the methods of the COM                  server object &lt;em&gt;Add( ) &lt;/em&gt;and &lt;em&gt;Subtract( )&lt;/em&gt; have been called using the                  interface pointer math obtained in the call to CoCreateInstance(                  ).   &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;Step 8: Uninitialize the COM                  Object. This is possibly the simplest job. Simply call the                  function &lt;em&gt;CoUninitialize( ) &lt;/em&gt;at the                  end of                  &lt;em&gt;InitInstance( )&lt;/em&gt; function as                  shown below:   &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt; BOOL                  CAtlClientApp::InitInstance( )&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt; // AppWizard generated code&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;CoUninitialize( ) ;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;              &lt;/span&gt;&lt;/blockquote&gt; &lt;p style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt; }&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;              &lt;/span&gt;&lt;/blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;            &lt;/span&gt;&lt;blockquote&gt; &lt;span style="font-family:arial;font-size:85%;"&gt;With that we are through with                  the creation of the client. Now you can compile and execute the                  client and check out whether it is able to interact with the                  methods in the server.   &lt;/span&gt;&lt;/blockquote&gt; &lt;ul&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;br /&gt;&lt;img src="http://www.kicit.com/freebies/com/atlcalculator.gif" width="429" height="236" /&gt; &lt;/span&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2252742141481837423-4924702079148005263?l=atlcomtutorial.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://atlcomtutorial.blogspot.com/feeds/4924702079148005263/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2252742141481837423&amp;postID=4924702079148005263' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2252742141481837423/posts/default/4924702079148005263'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2252742141481837423/posts/default/4924702079148005263'/><link rel='alternate' type='text/html' href='http://atlcomtutorial.blogspot.com/2008/08/building-server-and-client.html' title='Building Server And Client'/><author><name>sandy</name><uri>http://www.blogger.com/profile/02503582209971047801</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
