VCSamples/VC2010Samples/ComTypeLibfor7/freethrd at master · SimplexZhao/VCSamples · GitHub
Skip to content

Latest commit

 

History

History
 
 

Folders and files

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

<html><head><title>FREETHRD Sample: Multithreaded Client and Free-Threaded Server with Compiler COM Support</title></head><body><h1>FREETHRD Sample: Multithreaded Client and Free-Threaded Server with Compiler COM Support</h1><div id="mainSection"><div id="mainBody"><div id="allHistory" class="saveHistory" onsave="saveAll()" onload="loadAll()"></div><p /><p>This sample demonstrates a multithreaded client and free-threaded server with compiler COM support.</p><p>This sample consists of the following parts:  </p><ul><li><p>Freclien, a multithreaded client</p></li><li><p>Freserve, a free-threaded in-process server</p></li></ul><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"><div class="alert"><table width="100%" cellspacing="0" cellpadding="0"><tr><th align="left">Note </th></tr><tr><td><p>If you are running Visual C++ Express Edition, you might need to install the Platform SDK before running this sample. For information on how to do this, see <MSHelp:link keywords="971463b4-7178-42cc-87b4-566295b7ae50" tabindex="0" >How to: Use Visual C++ Express Edition with the Microsoft Platform SDK</MSHelp:link>.</p></td></tr></table></div><h4 class="subHeading">To build and run this sample</h4><div class="subSection"><ol><li><p>Open the solution freethrd.sln.</p></li><li><p>Build the server project and then build the client project.</p></li><li><p>Make the client project the startup project (right-click the project node and click <b>Set as StartUp Project</b>) and run the sample. </p></li></ol></div></div><h1 class="heading">How the Sample Works</h1><div id="sectionSection1" class="seeAlsoNoToggleSection"><p>The Freclien sample spawns multiple threads to create and use the <code>COBall</code> COM object provided by the Freserve free-threaded server. The <code>COBall</code> object itself spawns no threads; instead, it passively responds to <code>IBall</code> interface requests from many possible client threads. The Freclien client creates and controls one <code>COBall</code> object through the <code>IBall</code> interface that the object exposes. As three of Freclien's threads move the ball through calls to <code>IBall::Move</code>, the remaining main thread uses a system timer to obtain timed updates of the <code>COBall</code> object's position, size, and color. This main thread uses that data, obtained by calling <code>IBall::GetBall</code>, to display graphical snapshot images of the ball in the client's main window. </p><p>In the Freserve sample, the <code>COBall</code> object internally updates its color property to reflect the last thread that called the object's <code>Move</code> method. The display thread uses this data for each ball image it displays. As the ball moves, it changes color to reflect each thread that moves the ball. As the ball moves, it also leaves a trail that provides a striking visual history of these passing threads. This trail demonstrates that, with COM's free-threading model, every thread that makes interface requests to the same object accesses the object on the calling thread. Each different color of the single ball object represents a different calling thread.</p><p>This sample uses native compiler COM support. It gives an example of a custom COM interface that marshals the RECT and POINT structures with the free-threaded model. It demonstrates the use of the <b>exclude</b> attribute of the <b>#import</b> directive.</p></div></div><div id="footer"><div class="footerLine"></div>
          © Microsoft Corporation. All rights reserved.  Send <a href="mailto:DevDocs@microsoft.com?subject=Documentation Feedback :FREETHRD Sample: Multithreaded Client and Free-Threaded Server with Compiler COM Support">comments</a> about this topic to Microsoft.
      </div></div></body></html>