Skip to content
This repository was archived by the owner on Feb 9, 2021. It is now read-only.

Latest commit

 

History

History
<!--TO READ THIS HELP FILE, RIGHT-CLICK ON THE FILE NAME IN THE
    SOLUTION EXPLORER PANE AND SELECT "VIEW IN BROWSER"-->

<html><head><title>CONNECT Attributes Sample: Demonstrates Implementation and Use of Connection Points</title></head><body><h1>CONNECT Attributes Sample: Demonstrates Implementation and Use of Connection Points</h1><div id="mainSection"><div id="mainBody"><div id="allHistory" class="saveHistory" onsave="saveAll()" onload="loadAll()"></div><p /><p>The CONNECT attributes sample illustrates the implementation and use of connection points (the <b>IConnectionPointContainer</b> and <b>IConnectionPoint</b> interfaces) in a multithreaded environment.</p><p>The sample demonstrates several commonly used IDL, COM, and compiler attributes, including support_errorinfo, event_source, and event_receiver.</p><p>The <MSHelp:link keywords="E7FF3A37-A0ED-4578-A0A8-DF072817BA0D" tabindex="0" >CONNECT sample</MSHelp:link> is the nonattributed version of this sample.</p><div class="alert"><table width="100%" cellspacing="0" cellpadding="0"><tr><th align="left">Security Note </th></tr><tr><td><p>This sample code is provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices.</p></td></tr></table></div><h1 class="heading">Building and Running the Sample</h1><div id="sectionSection0" class="seeAlsoNoToggleSection"><h4 class="subHeading">To build and run this sample</h4><div class="subSection"><ol><li><p>Open the solution file connect.sln.</p></li><li><p>From the <b>Build</b> menu, click <b>Build Solution</b>.</p></li><li><p>Select which client you want to run, Drive or MDrive, and make it the startup project (right-click the project folder and click <b>Set as StartUp Project</b>). More information about the clients can be found in the How the Sample Works section.</p></li><li><p>On the <b>Debug</b> menu, click <b>Start Without Debugging</b>.</p></li></ol></div></div><h1 class="heading">How the Sample Works</h1><div id="sectionSection1" class="seeAlsoNoToggleSection"><p>The server is implemented in Connect.dll. This DLL allows the creation of a <code>CoRandom</code> COM object, implemented by the <code>CRandom</code> C++ class. The COM object supports <code>IRandom</code> (a dual interface) and <b>IConnectionPointContainer</b>, and it accepts connections for the <code>IRandomEvent</code> interface.</p><p>The <code>IRandom</code> interface supports the following methods:  </p><ul><li><p><code>Start</code> — starts a thread inside the object</p></li><li><p><code>Stop</code> — stops a thread inside the object</p></li><li><p><code>StopAll</code> — stops all of the running threads</p></li></ul><p>When running, the secondary threads inside the object keep firing events through the connection point.</p><p>Two clients are provided: Drive and MDrive. They can be found in the Drive and MDrive subdirectories.  </p><ul><li><p>Drive.exe is a simple console application that provides a single object implementing the <code>IRandomEvent</code> interface. It creates a <code>CoRandom</code> object, calls <code>Advise</code> and <code>Unadvise</code> on the connection point, and makes the <code>CoRandom</code> object fire events into the drive's object.</p></li><li><p>Mdrive.exe is an MFC dialog-based application, able to create multiple advise sinks and control the number of threads the server creates. When you run Mdrive.exe, click the <b>Start</b> button at least once, then click the <b>Advise</b> button several times. Each click of the <b>Advise</b> button adds a connection point, which makes the display wider. If you do not click the <b>Advise</b> button, you will not see any activity in the display. </p></li></ul></div><h1 class="heading">Attributes</h1><div id="sectionSection2" class="seeAlsoNoToggleSection"><p>This sample uses the following attributes:  </p><ul><li><p><b>Connect</b>   coclass, default, dll, dual, event_source, helpstring, id, in, module, name, object, out, pointer_default, progid, support_error_info, uuid, vi_progid</p></li><li><p><b>Connect/drive</b>   event_receiver, module</p></li></ul></div><h1 class="heading">Keywords</h1><div id="sectionSection3" class="seeAlsoNoToggleSection"><p>This sample uses the following keywords:</p><p>AfxGetApp; AfxMessageBox; AtlAdvise; ATLASSERT; AtlUnadvise; BEGIN_COM_MAP; BEGIN_CONNECTION_POINT_MAP; BEGIN_MESSAGE_MAP; BEGIN_OBJECT_MAP; CComCoClass; CComModule::GetClassObject; CComModule::GetLockCount; CComModule::Init; CComModule::RegisterServer; CComModule::Term; CComModule::UnregisterServer; CComObject::CreateInstance; CComObjectRoot; CDialog::OnCancel; CDialog::OnOK; CloseHandle; CoCreateInstance; COleTemplateServer::RegisterAll; COM_INTERFACE_ENTRY; COM_INTERFACE_ENTRY_IMPL; COM_INTERFACE_ENTRY2; CONNECTION_POINT_ENTRY; CoUninitialize; CreateEvent; CreateThread; DECLARE_REGISTRY_RESOURCEID; DisableThreadLibraryCalls; DoModal; DrawIcon; END_COM_MAP; END_CONNECTION_POINT_MAP; END_MESSAGE_MAP; END_OBJECT_MAP; GdiFlush; GetClientRect; GetDlgItem; GetTickCount; GetUnknown; IConnectionPointContainerImpl; IConnectionPointImpl; IDispatchImpl; ISupportErrorInfo; LoadIcon; Lock; memset; OBJECT_ENTRY; ON_COMMAND; puts; ReleaseDC; SendMessage; SetEvent; SetIcon; SetPixel; Sleep; Unadvise; Unlock; WaitForSingleObject</p><div class="alert"><table width="100%" cellspacing="0" cellpadding="0"><tr><th align="left">Note </th></tr><tr><td><p>Some of the samples, such as this one, have not been modified to reflect the changes in the Visual C++ wizards, libraries, and compiler, but still demonstrate how to complete your desired task. </p></td></tr></table></div></div></div><div id="footer"><div class="footerLine"></div>
          © Microsoft Corporation. All rights reserved.  Send <a href="mailto:DevDocs@microsoft.com?subject=Documentation Feedback :CONNECT Attributes Sample: Demonstrates Implementation and Use of Connection Points">comments</a> about this topic to Microsoft.
      </div></div></body></html>