15.02.2015 Views

C# 4 and .NET 4

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Using a CoM Component from a .neT Client ❘ 711<br />

coclass COMDemo<br />

{<br />

[default] interface IWelcome;<br />

interface IMath;<br />

[default, source] dispinterface _ICompletedEvents;<br />

};<br />

code snippet COMServer/COMServer.idl<br />

You can use a wizard to create an implementation that fires the event back to the client. Open the class view,<br />

select the class CComDemo, open the context menu, <strong>and</strong> select Add ➪ Add Connection Point . . . to start<br />

the Implement Connection Point Wizard (see Figure 26-10). Select the source interface ICompletedEvents<br />

for implementation with the connection point.<br />

figure 26-10<br />

The wizard creates the proxy class CProxy_ICompletedEvents to fire the events to the client. Also, the<br />

class CCOMDemo is changed. The class now inherits from IConnectionPointContainerImpl <strong>and</strong> the<br />

proxy class. The interface IConnectionPointContainer is added to the interface map, <strong>and</strong> a connection<br />

point map is added to the source interface _ICompletedEvents.<br />

class ATL_NO_VTABLE CCOMDemo:<br />

public CComObjectRootEx,<br />

public CComCoClass,<br />

public IDispatchImpl,<br />

public IDispatchImpl,<br />

public IConnectionPointContainerImpl,<br />

public CProxy_ICompletedEvents<br />

{<br />

public:<br />

//.<br />

BEGIN_COM_MAP(CCOMDemo)<br />

COM_INTERFACE_ENTRY(IWelcome)<br />

COM_INTERFACE_ENTRY(IMath)<br />

COM_INTERFACE_ENTRY2(IDispatch, IWelcome)<br />

COM_INTERFACE_ENTRY(IConnectionPointContainer)<br />

END_COM_MAP()<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!