Going Mobile with the Active Template Library

Outside of the Windows CE kernel where the C-style DLL prevails, COM is the most common technology used to expose key technology elements on embedded Windows devices. Many of the every-day activities that end-users perform with their Windows Mobile device are based on the COM architecture—ActiveSync, Pocket Outlook, Internet Explorer Mobile, the Soft Input Panel (SIP), and Windows Media Player all rely on COM as the primary integration technology. The C++ developer is uniquely placed to take advantage of these COM-based technologies, and the Active Template Library (ATL) is the best toolkit available for COM development.

COM and ATL are both huge topics, and have filled many previous books and articles. Rather than duplicate the already substantial body of literature that introduces COM and ATL, this article assumes some familiarity with COM and ATL development for the desktop and server environment, and primarily focuses on the subtle differences between the full version of COM and ATL and the Smart Device version.

Before drilling into the use of ATL to write COM components for Windows CE, it is worth briefly mentioning that ATL also simplifies COM programming when consuming components. COM relies on reference counts to determine when the memory associated with a component should be freed. The process of incrementing and decrementing the reference count of a COM object is a tedious and error-prone exercise, and ATL addresses this problem with the use of smart pointers. In a previous article, a Smart Device MFC project was shown that used Pocket Outlook to retrieve information about the time that was booked with appointments on a particular day. The project used standard interface pointers that required a call to Release to each interface before the interface pointer went out of scope.

To add ATL support to an existing MFC or Win32 project, simply bring up the project properties as shown in Figure 1, and select to statically or dynamically link to ATL. Static linking simplifies deployment, and is the recommended strategy for Smart Device projects. Once ATL support has been added, the raw interface pointers can be converted to ATL smart pointers by using the CComPtr template, so for the sample application, IPOutlookApp*, is replaced with CComPtr<IPOutlookApp>, and the call to Release can be removed.

Figure 1: Adding ATL Support to Existing Projects

Smart Device ATL for Component Authoring

For experienced ATL developers moving from the desktop world, the first thing that they will notice about the Smart Device ATL Project Wizard is the lack of Attribute support. Attributes have been part of the desktop version on ATL since Visual Studio 2002, and allows developers to concentrate of defining classes and interfaces directly in C++ rather than the COM-specific Interface Definition Language (IDL). In the absence of attributes, Visual Studio support for adding controls and classes reduces the burden of developers needing to gain a deep knowledge of IDL, and the addition of a COM object to a project inside Visual Studio adds the required IDL code in addition to the generation of the C++ class skeleton. However, like any code generation technique that adds code to a number of separate files, the real challenge comes when a control needs to be renamed or moved to a different project. In this case, using the IDE to generate the skeleton of the new class and interfaces is recommended, after which the method bodies can be moved across using cut-and-paste techniques.

Many of the difference between the desktop and mobile versions of ATL reflect underlying differences in the supported COM features on these platforms. Windows Mobile does not support the un-registration of COM components; theref0re, the code generated by the ATL application wizard is different for a Smart Device Project. A call to CAtlDllModuleT:DllUnregisterServer still exists in the generated code, but an extra parameter is passed to the method to instruct the ATL framework to ignore the call.

One of the critical differences between ATL objects on the desktop and device is how threading models work. As a brief background, the COM infrastructure allows a COM object to nominate one of a number of different threading models via a Registry setting. COM components that are not thread-safe or have strong thread affinity could elect to live in a single-threaded apartment (STA), and COM would use windows queues to synchronize the delivery of calls to the object. COM components that handled their own thread safety needs could elect to live in the multi-threaded apartment (MTA), and these components typically had better performance and greater scalability characteristics compared to STA-residing components. The problem for MTA components was that they still exhibited a performance-hit due to marshalling of calls to components living in STAs, and this gave rise to free-threaded components that could move from the MTA to STAs and back again. Free-threaded components are implemented using a technique known as aggregating the free-threaded marshaller, and in addition to the thread-safety requirements of free-threading, special techniques need to be used when holding interface pointers to COM objects (the COM global interface table and the ATL helper class CComGITPtr greatly simplify the work of dealing with member variable interface pointers—see the MSDN documentation on CComGITPtr for further details.)

The critical point for ATL developers is that a Smart Device Project for most builds of the Windows CE operating system does not ship with a full COM implementation, and this includes all Windows Mobile builds. According to the documentation, the slimmed-down version of COM "provides a midrange implementation of COM and OLE automation that supports only in-process free-threaded objects and requires about 100-200 KB of memory." When using Visual Studio 2005 or Visual Studio 2008 to add a new ATL object to a project, a similar dialog to the full version of ATL is displayed, as shown in Figure 2. The main difference between the Smart Device and desktop version of the dialog is the hyperlink to documentation, and following this hyperlink explains that the options related to threading models available don't apply to most CE platforms, including Windows Mobile. Regardless of the threading model selected in the dialog shown in Figure 2, a free-threaded component will be generated.

Figure 2: Adding a STL Simple Object to a Smart Device Project

Although the prospect of implementing a free-threaded component may not appear attractive to developers who have struggled with understanding the COM global interface table, it is worth noting that the complexities of needing to go between multiple STAs and the MTA do not exist in Windows Mobile because apartments are not present in the slimmed-down COM plumbing. The other point worth noting is that the primary use of COM on Windows Mobile is to integrate with and extend user interface elements such as the Soft Input Panel, Internet Explorer, and Media Player. In these scenarios, a COM component will be called on the user-interface thread, and will not be subject to the same level of multi-threading stress as a COM component in a server environment.

ATL simplifies the consumption and production of COM components, and the version of ATL available for Smart Device projects offers the bulk of functionality from the full ATL version. The COM implementation that ships with most builds of Windows CE, including all Windows Mobile builds, lacks many of COM's advanced features like apartments, and this simplifies the programming experience for C++ developers using ATL. For the C++ developer with some experience with templates and COM, Smart Device ATL offers a fast track for integrating with a range of Windows CE technologies.

About the Author

Nick Wienholt is an independent Windows and .NET consultant based in Sydney. He is the author of Maximizing .NET Performance and co-author of A Programmers Introduction to C# 2.0 from Apress, and specialises in system-level software architecture and development, with a particular focus of performance, security, interoperability, and debugging.

Nick is a keen and active participant in the .NET community. He is the co-founder of the Sydney Deep .NET User group and writes technical article for Australian Developer Journal, ZDNet, Pinnacle Publishing, CodeGuru, MSDN Magazine (Australia and New Zealand Edition) and the Microsoft Developer Network. An archive of Nick's SDNUG presentations, articles, and .NET blog is available at www.dotnetperformance.com.

In recognition of his work in the .NET area, he was awarded the Microsoft Most Valued Professional Award from 2002 through 2007.


  • Pas cher rose ghd en vente

    Posted by hjejgc505 on 07/16/2013 04:34am

    GHD Edition Limitée Noël Gift Set contient tout ce dont vous avez besoin précieux pour créer de superbes modèles saisonniers. La boîte est exquis pour trouver le cadeau parfait sous l'arbre. Vous trouverez dans la boîte de cadeau: argent et noir redresseurs ghd IV styler pas cher et sèche-cheveux Voyage sont présentés dans un beau sac paillettes roll-up rouleau métallique fermée avec une cravate de satin noir. Le fer à lisser et sèche-cheveux dans son propre individu résistant à la chaleur amovible avec fermeture à glissière est parfait pour les week-end célébration supplémentaire. Le sac de rouleau glamour sert aussi une surface résistante à la chaleur utile pour assurer la sécurité de style sur la route. [url=http://ghdpascherfer.hpage.com/]lisseur ghd styler[/url] Le ressort de la boutique, il est beaucoup Cheap GHD Norge.Our lisseur ghd pas seulement pas cher mais la qualité est Veldig soutien-gorge, est la meilleure product.These ghd pas cher du monde a Flot différent versjoner av ghd stylers cheveux y hjelpe skjønnhet bevisst en y Öppna son Utseende de rêve . Ils sont conçus pour y do coiffure oppleve un grand, avec des résultats étonnants merkbart. Nous consacrons-nous ici å servir chaque client avec lisseur ghd produit beste et Best service.and ces ghd droit Rod Price mer tiltrekke you.We pense que vous nageoire vos lisseur ghd pas cher de favoris. [url=http://bbeatsinorge.cabanova.com/]ghd pas cher[/url] The Amazing GHD Rich Ruby Red Metallic Collection cadeau vous définissez l'un des trois nouveaux Samlinger utgitt dans le cadre d'Metallic utvalg de GHD, pour Noël 2012. Il a donné vakre vu à l'intérieur de maison SUVEREN GHD Gold Classic Styler, dans un "Ruby Red Rich" effet finish.Advanced ovn technologie céramique métallique pour les résultats complets lisses, brillants. Tension universelle pour ytelse cohérente atteint Reiser. Plater noir élégant avec et SNEV de Gnisten pour le style ulempe-libre. Vink Lede plaqueur pour enklere Kröller og Bolger. Ekstra Tuyau ligne de crédit renouvelable 2.7m pour la liberté pendant styling.It vous egnet pour les types de cheveux alle

  • clarisonic pro 2012 pattern in pink

    Posted by iouwanzi on 06/05/2013 09:43pm

    [url=http://www.miaclarisonicaustralia.org/]clarisonic mia 2[/url] Introduktion til Beats by Dr. Dre Executive Hovedtelefoner Direktionen repræsenterer en ny karakteristisk, sofistikeret design for Beats By Dr. Dre brand, der fokuserer på håndværk ved hjælp af førsteklasses materialer såsom aluminium, rustfrit stål og læder. Den bløde læder pandebånd og komfortable ørekopper er designet til lange slid og en unik sammenfoldeligt design gør Beats Executive hovedtelefoner nem at bære on-the-go. Den administrerende har overlegen Active Noise Cancellation (ANC) performance, tunet til uafbrudt lytning nydelse ved 35.000 fod, og overalt i mellem og med iOS kompatibel mikrofon kabel, det giver fuld telefon funktionalitet, herunder besvar afslut, opkald venter, switching og stemmekommandoer . [url=http://www.australiaclarisonic.com/clarisonic-classic]clarisonic classic[/url] If inline controls for calls is a priority, consider checking out the RHA SA950i, which is even more affordable, and also has a more substantial bass response in comparison. The Polk Audio UltraFit 2000 is another budget on-ear option—more affordable than the Zoro with phone controls built into the earpieces, and as a bonus, it’s intended to withstand sweaty workouts. If you have a bit more room in your budget and still want an emphasis on clarity in the mids, and bass that isn’t wildly boosted, the Bowers & Wilkins P3 is a comfortable on-ear option with solid audio performance. [url=http://www.australiaclarisonic.com/]clarisonic mia[/url] Give indsigt i LOCOG tænkning, og måske om ikke dets juridiske team vil reagere forskelligt på Dr Dre har Beats hovedtelefoner stunt, en talsmand sagde dengang: “Vores tilgang til håndhævelse i 2006 loven har altid været fornuftig, pragmatisk og forholdsmæssige.”Vi er nødt til at beskytte rettighederne for vores sponsorer, der har betalt for at få eksklusive associationer til legene i deres sponsorater kategorier. Vi er hård på kommercielt misbrug, men vi ønsker ikke at gøre noget for at dæmpe ægte begejstring og spænding om Games .

  • Sjælden GHD IV Limited Edition

    Posted by cheneason on 05/30/2013 06:51am

    [url=http://www.beats-by-dre-espana.webs.com/]Beats by dre españa[/url] Vores online butik handling, du den billigste og Billige GHD Styler. Nogle gange er det faktisk vigtigt for en babe at købe Ghd Sjældne Styler anon hos grossister, arcade online eller fordi yderligere ghd glattejern. Det er acceptabelt for typer af hår. [url=http://www.beats-by-dr-dre-2013.webstarts.com/]comprar auriculares beats[/url] ghd fladjern også kendt som elektriske krydsfiner, er krydsfiner populært kaldes, er opvarmet af aktuelle ghd glattejern for MCH eller PTC varmelegeme eller varmt wire, aluminium eller keramik plade til at overføre varme. ghd glattejern, Guming Si Yi er at glatte håret, håret gennem varmeelement for varme, blødgøre, og derefter afkølet for at opnå formålet med glat hår. Nu ghd glattejern, glatte begge dele, og kan trække lydstyrken. Ghd glattejern før, den største bruger er en professionel salon barber, Europa og Amerika fra 2007 personer er kommet på hjemmemarkedet, til hår derhjemme kan være en SPA. Ghd glattejern vil nu ind på det danske hjemmemarked, vil være en væsentlig produkter til personlig pleje, ligesom kamme den samme popularitet. [url=http://www.cascos-beats-baratos.webs.com/]Cascos beats baratos[/url] Forsøg på blot ét bestemt biceps og også hænder og håndled, skal du for du gør brug af den særlige GHD Straightner, så du kan uden for de allerbedste indsættes inden den kræver ældgammelt inden for særskilte går tilbage. Gør brug af de faktiske tilsat fists som samt håndled og hænder skal evalueres ved hjælp af alle biceps og tricepsmusklerne såvel som hænder og håndled besiddelse håndled og hænder palms palm hånd spejl sammen med den til et par talrige forskellige andre forbrug hånden hænder og håndled udtryk at tænke over den særlige teknik, du vil højst sandsynligt være almindeligt affære. På grund af denne sandhed gode hår dage manke hår-styling metal salt er generelt ofte specialist merchandise, de ‘re gonna opnå grundlæggende reducere dit eget hår skakter. Skal nogen udfyldes forsøger blot 1 entydigt region, kunne video clip denne type op kommer som ser på situationen område indtil alle dine kommer tilbage igen hår er virkelig øjeblikkeligt.

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • As all sorts of data becomes available for storage, analysis and retrieval - so called 'Big Data' - there are potentially huge benefits, but equally huge challenges...
  • The agile organization needs knowledge to act on, quickly and effectively. Though many organizations are clamouring for "Big Data", not nearly as many know what to do with it...
  • Cloud-based integration solutions can be confusing. Adding to the confusion are the multiple ways IT departments can deliver such integration...

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date