<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress.com" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>interop &amp;laquo; WordPress.com Tag Feed</title>
	<link>http://en.wordpress.com/tag/interop/</link>
	<description>Feed of posts on WordPress.com tagged "interop"</description>
	<pubDate>Sun, 27 Dec 2009 01:16:39 +0000</pubDate>

	<generator>http://en.wordpress.com/tags/</generator>
	<language>en</language>

<item>
<title><![CDATA[Office Development in .NET is a Mess]]></title>
<link>http://dpaoliello.wordpress.com/2009/12/12/office-development-in-net-is-a-mess/</link>
<pubDate>Sat, 12 Dec 2009 10:43:22 +0000</pubDate>
<dc:creator>tehpenguin</dc:creator>
<guid>http://dpaoliello.wordpress.com/2009/12/12/office-development-in-net-is-a-mess/</guid>
<description><![CDATA[First off, a bit of a disclaimer &#8211; I admit that I am using Visual Studio 2010 (Beta 2) and Off]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>First off, a bit of a disclaimer &#8211; I admit that I am using Visual Studio 2010 (Beta 2) and Office 2010 (Beta); as such I shouldn&#8217;t expect all documentation for them to be complete or everything to being running bug free.</p>
<p>With that said: Begin the rant!</p>
<p>Today I decided to attempt to build an Outlook 2010 add in that would enable me to &#34;block&#34; particular authors on RSS Feeds. The reason I wanted to do this is that I am subscribed to the TechNet, ASP.NET, MSDN and Windows Team combined feeds &#8211; these 4 &#34;combined&#34; feeds are a collation of quite a number of blogs by Microsoft. The unfortunate thing is than a number of the blogs are completely irrelevant to me, or in a foreign language. With my Add In I could then block the non-English and irrelevant authors without having to create a-hundred-and-one &#34;rules&#34;. So, what went wrong?</p>
<p>First off, there is no &#34;RSS&#34; class.   <br />RSS items are of type PostItem or, more specifically, have a MessageClass or IPM.Post.RSS. So while it is possible to tell that an individual Post item is an RSS item (by doing a string comparison), its impossible to filter or check folders. This isn&#8217;t a *big* thing, but it certainly is very annoying.</p>
<p>Don&#8217;t use the classes, use the interfaces.   <br />For every VBA class, there is a .NET Interface AND a class; for instance there is an Outlook.PostItem (Interface) and Outlook.PostItemClass (Class). So which to use? Apparently the interface is the one to use, I think. The classes are apparently &#34;COM coclasses that are required for interoperability with the corresponding COM object&#34; &#8211; which to me sounds like an Infrastructure class, which is fine if it is private or internal, NOT public. Also, in case you didn&#8217;t notice, to add insult to injury there is a class with the word &#34;Class&#34; in its name that is referring to the fact it is a class (and the interface isn&#8217;t prefixed with an &#34;I&#34; &#8211; but we&#8217;ll forgive that).</p>
<p>The documentation is incomplete.   <br />And its not just the 2010 documentation that is incomplete. To use the example above, lets have a look at the <a href="http://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook.postitem_members.aspx" target="_blank">PostItem Interface members</a> (Go, click on the link and have a look. I&#8217;ll wait right here. Done?). That&#8217;s right &#8211; they&#8217;re empty. But IntelliSense in Visual Studio (and the actual API) tell a different story. Ok, lets assume that (being programmers) they&#8217;re lazy. maybe the documentation is in the <a href="http://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook.postitemclass_members.aspx" target="_blank">PostItemClass Class</a> (Again, click on the link&#8230;). Hmm&#8230;. apparently all of the Properties, Methods and Events do the same thing&#8230; which is the same thing as the Class&#8230;    <br />Oh, and in the name of fairness, reopen one of those links and check the version of Office the documentation is for. That&#8217;s right, 2007.</p>
<p>And, the Pièce de résistance:   <br />Apparently <a href="http://msdn.microsoft.com/en-us/library/cc313152.aspx" target="_blank">Outlook is now Access in Office 2010</a> (click on the &#34;Outlook 2010&#34; link) (also, <a href="http://cc.bingj.com/cache.aspx?q=microsoft+office+2010&#38;d=4698019959671090&#38;mkt=en-AU&#38;setlang=en-AU&#38;w=f547cbf7,ca25dba6" target="_blank">Bing&#8217;s cached version</a>, just in case)</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[What is ATT up to in the cloud?]]></title>
<link>http://bartongeorge.net/2009/12/09/what-is-att-up-to-in-the-cloud/</link>
<pubDate>Thu, 10 Dec 2009 03:59:47 +0000</pubDate>
<dc:creator>Barton George</dc:creator>
<guid>http://bartongeorge.net/2009/12/09/what-is-att-up-to-in-the-cloud/</guid>
<description><![CDATA[A couple of weeks ago I was in New York to visit customers and attend the co-located Interop and Web]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>A couple of weeks ago I was in New York to visit customers and attend the co-located Interop and Web 2.0 events.  One of the attendees/participants I got to know there was Joe Weinman, VP of ATT’s Business Solutions.  Joe has been focusing a lot on the cloud lately so I thought I&#8217;d put down for posterity his thoughts and explanation of what ATT is up to in this space.</p>
<p><span style='text-align:center; display: block;'><object width='425' height='350'><param name='movie' value='http://www.youtube.com/v/J_3j7Mdzudk&#038;rel=1&#038;fs=1&#038;showsearch=0&#038;hd=0' /><param name='allowfullscreen' value='true' /><param name='wmode' value='transparent' /><embed src='http://www.youtube.com/v/J_3j7Mdzudk&#038;rel=1&#038;fs=1&#038;showsearch=0&#038;hd=0' type='application/x-shockwave-flash' allowfullscreen='true' width='425' height='350' wmode='transparent'></embed></object></span></p>
<p><strong>Some of the topics that Joe tackles:</strong></p>
<ul>
<li>ATT’s evolving strategy involves mix of managed endpoints and a variety of network services as well as a variety of services in the cloud.</li>
<li>ATT&#8217;s services range from infrastructure services like &#8220;Synaptic hosting,&#8221; storage as a service and compute as a service thru a variety of SaaS apps like unified comms and collaboration,  SAP,  Oracle ebiz suite, Seybold and JD Edwards.</li>
<li>They have a large platform as a service offering that is used by tens of thousands developers creating at mobile enterprise apps.</li>
<li>They target a wide variety of endpoints e.g.  iphones,windows mobile devices,  netbooks, black berries  all the way thru tele-presence rooms.</li>
<li>How ATT delivers on both front end and back end architectures.</li>
</ul>
<p>Pau for now&#8230;</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Webinar *Today* at 11am PT / 2pm ET ]]></title>
<link>http://wifijedi.com/2009/12/02/webinar-today-at-11am-pt-2pm-et/</link>
<pubDate>Wed, 02 Dec 2009 07:01:00 +0000</pubDate>
<dc:creator>wifijedi</dc:creator>
<guid>http://wifijedi.com/2009/12/02/webinar-today-at-11am-pt-2pm-et/</guid>
<description><![CDATA[The Burton Group and Xirrus are offering a FREE educational webinar today (Wednesday, Dec 2nd) on th]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>The Burton Group and Xirrus are offering a FREE educational webinar today (Wednesday, Dec 2nd) on the newly ratified IEEE wireless standard, 802.11n.  I delivered the Xirrus portion of this presentation at INTEROP New York a couple weeks ago, so I can tell you it&#8217;s packed with great information.  <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h2>“802.11n: Lessons Learned from the First 1,000 Xirrus Installations”</h2>
<p><strong>Date:</strong> Wednesday, December 2, 2009<br />
<strong>Time</strong>: 11:00 am PT / 2:00 pm ET / 7:00 pm UK</p>
<p><strong> </strong></p>
<p><strong>Speakers:</strong></p>
<p>Paul DeBeasi, Senior Analyst, Burton Group</p>
<p>Kurt Sauter, Director of Product Marketing, Xirrus</p>
<p>The webinar is posted on the Xirrus webinars page: <a href="http://www.xirrus.com/library/webinars.php">http://www.xirrus.com/library/webinars.php</a></p>
<p><strong>You can use the below to register:</strong></p>
<p><a href="http://event.on24.com/r.htm?e=180563&#38;s=1&#38;k=6A1C2263406C5508E18B12C79EF90978">http://event.on24.com/r.htm?e=180563&#38;s=1&#38;k=6A1C2263406C5508E18B12C79EF90978</a></p>
<p>This webinar will discuss:</p>
<p>• Features that the first generation 11n products provide<br />
• Site Survey Issues<br />
• Performance Expectations<br />
• Network and Architecture Considerations<br />
• Client Device Considerations<br />
• Security Issues<br />
• Overall Recommendations</p>
<p>The webinar will be archived on the Xirrus website, and anyone will be able to listen/view after the live event.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[David Pogue channels Britney Spears]]></title>
<link>http://brainstormtech.blogs.fortune.cnn.com/2009/11/18/david-pogue-channels-britney-spears/</link>
<pubDate>Wed, 18 Nov 2009 17:17:45 +0000</pubDate>
<dc:creator>Philip Elmer-DeWitt</dc:creator>
<guid>http://brainstormtech.blogs.fortune.cnn.com/2009/11/18/david-pogue-channels-britney-spears/</guid>
<description><![CDATA[The New York Times&#8217; columnist entertains IT types with a parody of &#8220;Ooops!&#8230; I did ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><strong>The New York Times&#8217; columnist entertains IT types with a parody of &#8220;Ooops!&#8230; I did it again.&#8221; </strong></p>
<div id="attachment_15394" class="wp-caption alignright" style="width: 310px"><a href="http://fortunebrainstormtech.wordpress.com/files/2009/11/pogue-still.png"><img class="size-medium wp-image-15394" title="Pogue still" src="http://fortunebrainstormtech.wordpress.com/files/2009/11/pogue-still.png?w=300" alt="" width="300" height="225" /></a><p class="wp-caption-text">Pogue at Interop. Photo: Philip Elmer-DeWitt</p></div>
<p>David Pogue may review technology for a living, but give him half a chance and he&#8217;ll revert to his first love: show tunes.</p>
<p>He did it again Wednesday, ending his Interop New York 2009 keynote at the Javits Center with one of his patented song parodies: &#8220;Apps!&#8230; I did it again,&#8221; a Britney Spears classic (if there is such a thing) rewritten for the age of the Apple (<a href="http://money.cnn.com/quote/quote.html?symb=AAPL">AAPL</a>) iPhone.</p>
<p>The performance followed an address that entertained mostly by accident. In what he described in advance as an &#8220;exercise in idiocy,&#8221; he attempted 15 live demos of his favorite gadgets and apps.</p>
<p>We lost track of how many failed, but it seemed like more than half. &#8220;Dr. Kevorkian, call me now!&#8221; he cried after one of his simplest &#8212; a demo of Google Info (800-GOOG-411) &#8212; was foiled by Interop&#8217;s overloaded Wi-Fi circuits.</p>
<p>Below the fold: Pogue at the electric piano.</p>
<p><!--more--></p>
<p><span style='text-align:center; display: block;'><object width='425' height='350'><param name='movie' value='http://www.youtube.com/v/F9POug3kHtQ&#038;rel=1&#038;fs=1&#038;showsearch=0&#038;hd=0' /><param name='allowfullscreen' value='true' /><param name='wmode' value='transparent' /><embed src='http://www.youtube.com/v/F9POug3kHtQ&#038;rel=1&#038;fs=1&#038;showsearch=0&#038;hd=0' type='application/x-shockwave-flash' allowfullscreen='true' width='425' height='350' wmode='transparent'></embed></object></span></p>
<p>UPDATE: Pogue helpfully provided by e-mail this list of the 14 demos he attempted (one got cut for time):</p>
<p>* Mifi<br />
* iPhone Touch as a cellphone (using Mifi+Skype Out)<br />
* 800-Goog 411<br />
* Blurt (for BlackBerry)&#8211;video chat with the author in Dallas<br />
* Nikon Coolpix 1000pj (camera with projector)<br />
* Ocarina (musical instrument iPhone app)<br />
* I Am T-Pain<br />
* Jaadu VNC (real-time control of Mac/PC/Linux across the Internet on phone)<br />
* Red Laser (barcode scan/comparative price lookup)<br />
* PushIt2Me (&#8220;push&#8221; notification of urgent email&#8211;wakes the iPhone)<br />
* RunPee Mobile (tells you exactly when, in each movie, you can go pee)<br />
* FakeCalls<br />
* Retina (augmented reality for the color-blind)<br />
* Swine Flu AR (mockup of phony future app)</p>
<p>See also:</p>
<ul>
<li><a href="http://brainstormtech.blogs.fortune.cnn.com/2009/10/25/video-dont-cry-for-me-cupertino/">Video: &#8220;Don&#8217;t Cry for Me Cupertino&#8221;</a></li>
<li><a href="http://brainstormtech.blogs.fortune.cnn.com/2009/01/07/pogue-rocks-macworld-with-where-is-steve/">Pogue rocks Macworld with &#8220;Where is Steve?&#8221;</a></li>
</ul>
<p>[Follow Philip Elmer-DeWitt on Twitter @<a rel="external nofollow" href="http://twitter.com/philiped" target="new">philiped</a>]</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Para Bellum Web]]></title>
<link>http://lewisshepherd.wordpress.com/2009/11/17/para-bellum-web/</link>
<pubDate>Tue, 17 Nov 2009 13:09:23 +0000</pubDate>
<dc:creator>lewisshepherd</dc:creator>
<guid>http://lewisshepherd.wordpress.com/2009/11/17/para-bellum-web/</guid>
<description><![CDATA[Tim O&#39;Reilly, Ray Ozzie Tim O&#8217;Reilly created a bit of a stir last night in the tech world ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><div id="attachment_1783" class="wp-caption alignleft" style="width: 132px"><a href="http://lewisshepherd.wordpress.com/files/2009/11/oreillyozzie.jpg"><img class="size-full wp-image-1783" title="OReillyOzzie" src="http://lewisshepherd.wordpress.com/files/2009/11/oreillyozzie.jpg" alt="" width="122" height="83" /></a><p class="wp-caption-text">Tim O&#39;Reilly, Ray Ozzie</p></div>
<p>Tim O&#8217;Reilly created a bit of a stir last night in the tech world by writing a thoughtful essay entitled &#8220;<a href="http://radar.oreilly.com/2009/11/the-war-for-the-web.html" target="_blank">The War for the Web</a>.&#8221; He&#8217;ll be expanding on his thoughts in his keynote address today at the <a href="http://www.web2expo.com/webexny2009/" target="_blank">Web 2.0 Expo in New York</a>. From the essay, here&#8217;s the core argument:</p>
<blockquote><p>&#8220;[W]e&#8217;ve grown used to a world with one dominant search engine, one dominant online encyclopedia, one dominant online retailer, one dominant auction site, one dominant online classified site, and we&#8217;ve been readying ourselves for one dominant social network. But what happens when a company with one of these natural monopolies uses it to gain dominance in other, adjacent areas? I&#8217;ve been watching with a mixture of admiration and alarm as Google has taken their dominance in search and used it to take control of other, adjacent data-driven applications.</p>
<p>It could be that everyone will figure out how to play nicely with each other, and we&#8217;ll see a continuation of the interoperable web model we&#8217;ve enjoyed for the past two decades. But<strong> I&#8217;m betting that things are going to get ugly. We&#8217;re heading into a war for control of the web. And in the end, it&#8217;s more than that, it&#8217;s a war <em>against</em> the web as an interoperable platform</strong>. [<em>emphasis added</em>] Instead, we&#8217;re facing the prospect of Facebook as the platform, Apple as the platform, Google as the platform, Amazon as the platform, where big companies slug it out until one is king of the hill.</p>
<p>&#8230; P.S. One prediction: Microsoft will emerge as a champion of the open web platform, supporting interoperable web services from many independent players, much as IBM emerged as the leading enterprise backer of Linux.</p></blockquote>
<p><!--more-->The coda there, with the Microsoft prediction, is what fascinated me &#8211; so much so that I mentioned it on Twitter. <a href="http://twitter.com/timoreilly/status/5778836784" target="_blank">Tim immmediately responded</a>, <em>&#8220;Thanks. I should write a followup explaining the logic that got me to the PS.&#8221;</em>  While we wait for that, though, here&#8217;s my prediction &#8211; with a bit of inside knowledge &#8211; today Microsoft begins to live up to Tim&#8217;s expectations with several announcements at our Professional Developers Conference (PDC) 2009 in Los Angeles.</p>
<p>If you want to see the future of Microsoft, and the future of the web and computing as we see it, watch live as Ray Ozzie lays it out in his keynote address, streamed live today at 11:30 eastern time, 8:30 am Pacific, over at <a href="http://microsoftpdc.com/">http://microsoftpdc.com/</a>.</p>
<p>Oh &#8211; and if your Latin is rusty, my title above comes from the phrase &#8221;Si vis pacem, para bellum&#8221; &#8211; the classic doctrine of maintaining peace &#38; deterring war by being better armed and prepared. <a href="http://en.wikipedia.org/wiki/Si_vis_pacem,_para_bellum" target="_blank">It is generally attributed to Publius Flavius Vegetius Renatus</a>, a fourth-century AD Roman military scholar whom I consider the Sun Tzu of the West. I&#8217;ve known many fans of his philosophy in the Pentagon.</p>
<p>Now it may turn out that, whether they know it or not, Microsoft techies are building new ways to avoid a war on the open web. <a href="http://en.wikiquote.org/wiki/Sun_Tzu" target="_blank">As Sun Tzu wrote</a>,  &#8221;To win one hundred victories in one hundred battles is not the acme of skill. To subdue an enemy without fighting is the acme of skill.&#8221; Watch our PDC this week to see examples of what I consider the modern technological acme of skill.</p>
<p><a href="http://twitter.com/home/?status=blogpost on the War for the Web and PDC09 by @lewisshepherd:+http://bit.ly/qK3dO" target="_blank">Share this post on Twitter</a></p>
<p><a href="mailto:?Subject=Interesting%20post%20on%20the%20Shepherds%20Pi%20blog&#38;Body=Thought you might enjoy this, http://lewisshepherd.wordpress.com/2009/11/17/para-bellum-web/">Email this post to a friend</a></p>
<p><!-- AddThis Bookmark Button BEGIN --><a title="Bookmark using any bookmark manager!" href="http://www.addthis.com/bookmark.php" target="_blank"><span style="text-decoration:none;"><img src="http://s9.addthis.com/button1-share.gif" border="0" alt="AddThis Social Bookmark Button" width="125" /></span></a></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[C# Dynamic &ndash; C# 4.0/2010 New Feature]]></title>
<link>http://goldmanalpha.wordpress.com/2009/11/15/c-dynamic-2010-new-feature/</link>
<pubDate>Sun, 15 Nov 2009 16:46:42 +0000</pubDate>
<dc:creator>goldmanalpha</dc:creator>
<guid>http://goldmanalpha.wordpress.com/2009/11/15/c-dynamic-2010-new-feature/</guid>
<description><![CDATA[I watched the video about the new Dynamic feature coming in .Net 4.0.  Its an interview with Sam Ng ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>I watched <a href="http://channel9.msdn.com/posts/CharlieCalvert/CSharp-4-Dynamic-with-Chris-Burrows-and-Sam-Ng/">the video</a> about the new Dynamic feature coming in .Net 4.0.  Its an interview with Sam Ng and Chris Burrows who are the compiler developers who actually helped design and implement the feature.</p>
<blockquote><p>This feature provides enhanced interoperation with dynamic languages such as Ruby and Python, with dynamic models such as Silverlight JavaScript, and with COM objects, particularly those that you find in the Office APIs. With the addition of Dynamic to C# 4.0, it is now much easier to access Microsoft Office APIs from C#.</p></blockquote>
<p>They almost lost me when they said it was for interop &#38; COM (features I hope to avoid), but they brought me back when they mentioned it would be helpful with the HTML DOM and Office (features that keep sucking me back in).</p>
<p>They talked about the <a href="http://www.codeplex.com/dlr">DLR</a> (dynamic language runtime) which helps with dynamic expressions.  Lots of mentions of interop with <a href="http://www.codeplex.com/IronPython" target="_blank">IronPython</a> &#38; <a href="http://www.ruby-lang.org/en/" target="_blank">Ruby</a> so we’ll see if this makes those guys happy or is just a red herring.</p>
<p>There’s going to be a dynamic type: its <a href="http://en.wikipedia.org/wiki/Syntactic_sugar" target="_blank">syntactic sugar</a> for object type (I’m in favor of anything sweet).  Dynamic type will help the compiler optimize, but the syntax will be the same as usual.  This is primarily for COM Interop, Dynamic C#/Reflection, and Office API’s.</p>
<p>Dynamic will allow for working with dynamic objects without all that nasty casting, but you need to know method names in that case, so it sounds like you wont get intellisense <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> , and late bound type errors aren’t pretty either.  While getting the same error at runtime as you would at compile time sounds good, the bad part is that you’ll get an error at runtime.  More debugging…</p>
<p>Another use case is using a dynamic object (essentially an object type) as a parameter and the proper overload being determined at runtime.  Oh joy, imagine all the possibilities.  Now test them all…</p>
<p>On the other hand, if you really need to do this, it sounds like dynamic will help make things easier without much trouble for the developer.  I’m all for that.</p>
<p>I bet one day I’ll use this.  I hope I won’t build something embarrassing or that I regret.  At least I feel smarter listening to these guys talk.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Calling Assembly Language from WPF Program]]></title>
<link>http://zamjad.wordpress.com/2009/11/10/calling-assembly-language-from-wpf-program/</link>
<pubDate>Wed, 11 Nov 2009 03:31:27 +0000</pubDate>
<dc:creator>zamjad</dc:creator>
<guid>http://zamjad.wordpress.com/2009/11/10/calling-assembly-language-from-wpf-program/</guid>
<description><![CDATA[We can’t directly call Assembly language from WPF program. But we can do this indirectly. We can eas]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>We can’t directly call Assembly language from WPF program. But we can do this indirectly. We can easily call the assembly language from any VC++ unmanaged program and make a DLL of it and export it as a C functions. After that we can call the functions of that DLL just like we call the windows API. </p>
<p>Now lets take a look at the example. First we are going to make a simple DLL, which export C function and uses inline assembly. We have 5 function to perform some low level work for us. Here is a header file of our DLL.</p>
<pre style="border-bottom:#cecece 1px solid;border-left:#cecece 1px solid;background-color:#fbfbfb;min-height:40px;width:450px;overflow:auto;border-top:#cecece 1px solid;border-right:#cecece 1px solid;padding:5px;">
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  1:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  2: #ifndef __SYSINFO_H
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  3: #define __SYSINFO_H
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  4:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  5: <span style="color:#0000ff;">extern</span> &#34;<span style="color:#8b0000;">C</span>&#34; __declspec(dllexport) <span style="color:#0000ff;">int</span> __stdcall getCPUSpeed();
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  6: <span style="color:#0000ff;">extern</span> &#34;<span style="color:#8b0000;">C</span>&#34; __declspec(dllexport) <span style="color:#0000ff;">char</span>* __stdcall getCPUType();
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  7: <span style="color:#0000ff;">extern</span> &#34;<span style="color:#8b0000;">C</span>&#34; __declspec(dllexport) <span style="color:#0000ff;">int</span> __stdcall getCPUFamily();
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  8: <span style="color:#0000ff;">extern</span> &#34;<span style="color:#8b0000;">C</span>&#34; __declspec(dllexport) <span style="color:#0000ff;">int</span> __stdcall getCPUModel();
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  9: <span style="color:#0000ff;">extern</span> &#34;<span style="color:#8b0000;">C</span>&#34; __declspec(dllexport) <span style="color:#0000ff;">int</span> __stdcall getCPUStepping();
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 10:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 11: #endif
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 12: </pre>
</pre>
<p>Here is a implementation of these function. Here we have some low level assembly language work. </p>
<pre style="border-bottom:#cecece 1px solid;border-left:#cecece 1px solid;background-color:#fbfbfb;min-height:40px;width:450px;overflow:auto;border-top:#cecece 1px solid;border-right:#cecece 1px solid;padding:5px;">
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  1: #include &#34;<span style="color:#8b0000;">SysInfo.h</span>&#34;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  2: #include &#60;windows.h&#62;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  3:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  4: BOOL __stdcall DllMain(HINSTANCE hInst, DWORD dwReason, LPVOID lpReserved)
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  5: {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  6: 	<span style="color:#0000ff;">return</span>  TRUE;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  7: }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  8:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  9: <span style="color:#0000ff;">extern</span> &#34;<span style="color:#8b0000;">C</span>&#34; __declspec(dllexport) <span style="color:#0000ff;">int</span> __stdcall getCPUSpeed()
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 10: {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 11: 	LARGE_INTEGER ulFreq, ulTicks, ulValue, ulStartCounter, ulEAX_EDX, ulResult;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 12:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 13: 	<span style="color:#008000;">// it is number of ticks per seconds</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 14: 	QueryPerformanceFrequency(&#38;ulFreq);
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 15:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 16: 	<span style="color:#008000;">// current valueofthe performance counter</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 17: 	QueryPerformanceCounter(&#38;ulTicks);
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 18:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 19: 	<span style="color:#008000;">// calculate one second interval</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 20: 	ulValue.QuadPart = ulTicks.QuadPart + ulFreq.QuadPart;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 21:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 22: 	<span style="color:#008000;">// read time stamp counter</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 23: 	<span style="color:#008000;">// this asm instruction load the highorder 32 bit of the register into EDX</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 24: 	<span style="color:#008000;">// and the lower order 32 bits into EAX</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 25: 	_asm
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 26: 	{
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 27: 		rdtsc
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 28: 		mov ulEAX_EDX.LowPart, EAX
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 29: 		mov ulEAX_EDX.HighPart, EDX
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 30: 	}
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 31:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 32: 	<span style="color:#008000;">// start no of ticks</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 33: 	ulStartCounter.QuadPart = ulEAX_EDX.QuadPart;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 34:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 35: 	<span style="color:#008000;">// loop for 1 second</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 36: 	<span style="color:#0000ff;">do</span> {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 37: 		QueryPerformanceCounter(&#38;ulTicks);
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 38: 	} <span style="color:#0000ff;">while</span> (ulTicks.QuadPart &#60;= ulValue.QuadPart);
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 39:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 40: 	<span style="color:#008000;">// get the actual no of ticks</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 41: 	_asm {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 42: 		rdtsc
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 43: 		mov ulEAX_EDX.LowPart, EAX
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 44: 		mov ulEAX_EDX.HighPart, EDX
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 45: 	}
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 46:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 47: 	<span style="color:#008000;">// calculate result</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 48: 	ulResult.QuadPart = ulEAX_EDX.QuadPart - ulStartCounter.QuadPart;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 49:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 50: 	<span style="color:#0000ff;">return</span> (<span style="color:#0000ff;">int</span>)ulResult.QuadPart / 1000000;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 51: }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 52:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 53: <span style="color:#0000ff;">extern</span> &#34;<span style="color:#8b0000;">C</span>&#34; __declspec(dllexport) <span style="color:#0000ff;">char</span>* __stdcall getCPUType()
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 54: {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 55: 	<span style="color:#0000ff;">static</span> <span style="color:#0000ff;">char</span> pszCPUType[13];
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 56: 	memset(pszCPUType, 0, 13);
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 57:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 58: 	_asm
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 59: 	{
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 60: 		mov eax, 0
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 61: 		cpuid
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 62:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 63: 		<span style="color:#008000;">// getting information from EBX</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 64: 		mov pszCPUType[0], bl
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 65: 		mov pszCPUType[1], bh
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 66:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 67: 		ror  ebx, 16
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 68: 		mov pszCPUType[2], bl
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 69: 		mov pszCPUType[3], bh
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 70:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 71: 		<span style="color:#008000;">// getting information from EDX</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 72: 		mov pszCPUType[4], dl
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 73: 		mov pszCPUType[5], dh
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 74:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 75: 		ror  edx, 16
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 76: 		mov pszCPUType[6], dl
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 77: 		mov pszCPUType[7], dh
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 78:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 79: 		<span style="color:#008000;">// getting information from ECX</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 80: 		mov pszCPUType[8], cl
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 81: 		mov pszCPUType[9], ch
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 82:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 83: 		ror  ecx, 16
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 84: 		mov pszCPUType[10], cl
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 85: 		mov pszCPUType[11], ch
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 86: 	}
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 87:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 88: 	pszCPUType[12] = '';
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 89:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 90: 	<span style="color:#0000ff;">return</span> pszCPUType;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 91: }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 92:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 93: <span style="color:#0000ff;">extern</span> &#34;<span style="color:#8b0000;">C</span>&#34; __declspec(dllexport) <span style="color:#0000ff;">int</span> __stdcall getCPUFamily()
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 94: {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 95: 	<span style="color:#0000ff;">int</span> retVal;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 96:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 97: 	_asm {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 98: 		mov eax, 1
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 99: 		cpuid
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">100: 		mov retVal, eax
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">101: 	}
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">102:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">103: 	<span style="color:#0000ff;">return</span> (retVal &#62;&#62; 8);
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">104: }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">105:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">106: <span style="color:#0000ff;">extern</span> &#34;<span style="color:#8b0000;">C</span>&#34; __declspec(dllexport) <span style="color:#0000ff;">int</span> __stdcall getCPUModel()
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">107: {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">108: 	<span style="color:#0000ff;">int</span> retVal;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">109:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">110: 	_asm {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">111: 		mov eax, 1
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">112: 		cpuid
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">113: 		mov retVal, eax
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">114: 	}
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">115:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">116: 	<span style="color:#0000ff;">return</span> ((retVal &#62;&#62; 4 ) &#38; 0x0000000f);
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">117: }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">118:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">119: <span style="color:#0000ff;">extern</span> &#34;<span style="color:#8b0000;">C</span>&#34; __declspec(dllexport) <span style="color:#0000ff;">int</span> __stdcall getCPUStepping()
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">120: {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">121: 	<span style="color:#0000ff;">int</span> retVal;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">122:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">123: 	_asm {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">124: 		mov eax, 1
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">125: 		cpuid
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">126: 		mov retVal, eax
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">127: 	}
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">128:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">129: 	<span style="color:#0000ff;">return</span> (retVal &#38; 0x0000000f);
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">130: }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">131: </pre>
</pre>
<p>Now we are going to call these function just like Windows API using the PInvoke functionality. Here is a XAML file for the client of this DLL. </p>
<pre style="border-bottom:#cecece 1px solid;border-left:#cecece 1px solid;background-color:#fbfbfb;min-height:40px;width:450px;overflow:auto;border-top:#cecece 1px solid;border-right:#cecece 1px solid;padding:5px;">
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  1: <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">Window</span> <span style="color:#ff0000;">x</span>:<span style="color:#ff0000;">Class</span>=<span style="color:#0000ff;">&#34;AsmWpf.Window1&#34;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  2:     <span style="color:#ff0000;">xmlns</span>=<span style="color:#0000ff;">&#34;http://schemas.microsoft.com/winfx/2006/xaml/presentation&#34;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  3:     <span style="color:#ff0000;">xmlns</span>:<span style="color:#ff0000;">x</span>=<span style="color:#0000ff;">&#34;http://schemas.microsoft.com/winfx/2006/xaml&#34;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  4:     <span style="color:#ff0000;">Title</span>=<span style="color:#0000ff;">&#34;Assembly Language from WPF&#34;</span> <span style="color:#ff0000;">Height</span>=<span style="color:#0000ff;">&#34;300&#34;</span> <span style="color:#ff0000;">Width</span>=<span style="color:#0000ff;">&#34;400&#34;</span> <span style="color:#ff0000;">Background</span>=<span style="color:#0000ff;">&#34;AliceBlue&#34;</span> <span style="color:#ff0000;">Loaded</span>=<span style="color:#0000ff;">&#34;Window_Loaded&#34;</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  5:     <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">Grid</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  6:         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">Grid.RowDefinitions</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  7:             <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">RowDefinition</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  8:             <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">RowDefinition</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  9:             <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">RowDefinition</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 10:             <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">RowDefinition</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 11:             <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">RowDefinition</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 12:             <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">RowDefinition</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 13:         <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">Grid.RowDefinitions</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 14:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 15:         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">Grid.ColumnDefinitions</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 16:             <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">ColumnDefinition</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 17:             <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">ColumnDefinition</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 18:         <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">Grid.ColumnDefinitions</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 19:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 20:         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">TextBlock</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Column</span>=<span style="color:#0000ff;">&#34;0&#34;</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Row</span>=<span style="color:#0000ff;">&#34;0&#34;</span> <span style="color:#ff0000;">Margin</span>=<span style="color:#0000ff;">&#34;5&#34;</span> <span style="color:#ff0000;">VerticalAlignment</span>=<span style="color:#0000ff;">&#34;Center&#34;</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 21:             Computer Speed
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 22:         <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">TextBlock</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 23:         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">TextBlock</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Column</span>=<span style="color:#0000ff;">&#34;1&#34;</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Row</span>=<span style="color:#0000ff;">&#34;0&#34;</span> <span style="color:#ff0000;">Margin</span>=<span style="color:#0000ff;">&#34;5&#34;</span> <span style="color:#ff0000;">VerticalAlignment</span>=<span style="color:#0000ff;">&#34;Center&#34;</span> <span style="color:#ff0000;">Name</span>=<span style="color:#0000ff;">&#34;txtSpeed&#34;</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 24:         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">TextBlock</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Column</span>=<span style="color:#0000ff;">&#34;0&#34;</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Row</span>=<span style="color:#0000ff;">&#34;1&#34;</span> <span style="color:#ff0000;">Margin</span>=<span style="color:#0000ff;">&#34;5&#34;</span> <span style="color:#ff0000;">VerticalAlignment</span>=<span style="color:#0000ff;">&#34;Center&#34;</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 25:             Vendor Name
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 26:         <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">TextBlock</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 27:         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">TextBlock</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Column</span>=<span style="color:#0000ff;">&#34;1&#34;</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Row</span>=<span style="color:#0000ff;">&#34;1&#34;</span> <span style="color:#ff0000;">Margin</span>=<span style="color:#0000ff;">&#34;5&#34;</span> <span style="color:#ff0000;">VerticalAlignment</span>=<span style="color:#0000ff;">&#34;Center&#34;</span> <span style="color:#ff0000;">Name</span>=<span style="color:#0000ff;">&#34;txtVendor&#34;</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 28:         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">TextBlock</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Column</span>=<span style="color:#0000ff;">&#34;0&#34;</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Row</span>=<span style="color:#0000ff;">&#34;2&#34;</span> <span style="color:#ff0000;">Margin</span>=<span style="color:#0000ff;">&#34;5&#34;</span> <span style="color:#ff0000;">VerticalAlignment</span>=<span style="color:#0000ff;">&#34;Center&#34;</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 29:             Family
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 30:         <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">TextBlock</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 31:         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">TextBlock</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Column</span>=<span style="color:#0000ff;">&#34;1&#34;</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Row</span>=<span style="color:#0000ff;">&#34;2&#34;</span> <span style="color:#ff0000;">Margin</span>=<span style="color:#0000ff;">&#34;5&#34;</span> <span style="color:#ff0000;">VerticalAlignment</span>=<span style="color:#0000ff;">&#34;Center&#34;</span> <span style="color:#ff0000;">Name</span>=<span style="color:#0000ff;">&#34;txtFamily&#34;</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 32:         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">TextBlock</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Column</span>=<span style="color:#0000ff;">&#34;0&#34;</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Row</span>=<span style="color:#0000ff;">&#34;3&#34;</span> <span style="color:#ff0000;">Margin</span>=<span style="color:#0000ff;">&#34;5&#34;</span> <span style="color:#ff0000;">VerticalAlignment</span>=<span style="color:#0000ff;">&#34;Center&#34;</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 33:             Model
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 34:         <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">TextBlock</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 35:         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">TextBlock</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Column</span>=<span style="color:#0000ff;">&#34;1&#34;</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Row</span>=<span style="color:#0000ff;">&#34;3&#34;</span> <span style="color:#ff0000;">Margin</span>=<span style="color:#0000ff;">&#34;5&#34;</span> <span style="color:#ff0000;">VerticalAlignment</span>=<span style="color:#0000ff;">&#34;Center&#34;</span> <span style="color:#ff0000;">Name</span>=<span style="color:#0000ff;">&#34;txtModel&#34;</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 36:         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">TextBlock</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Column</span>=<span style="color:#0000ff;">&#34;0&#34;</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Row</span>=<span style="color:#0000ff;">&#34;4&#34;</span> <span style="color:#ff0000;">Margin</span>=<span style="color:#0000ff;">&#34;5&#34;</span> <span style="color:#ff0000;">VerticalAlignment</span>=<span style="color:#0000ff;">&#34;Center&#34;</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 37:             Stepping
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 38:         <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">TextBlock</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 39:         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">TextBlock</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Column</span>=<span style="color:#0000ff;">&#34;1&#34;</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Row</span>=<span style="color:#0000ff;">&#34;4&#34;</span> <span style="color:#ff0000;">Margin</span>=<span style="color:#0000ff;">&#34;5&#34;</span> <span style="color:#ff0000;">VerticalAlignment</span>=<span style="color:#0000ff;">&#34;Center&#34;</span> <span style="color:#ff0000;">Name</span>=<span style="color:#0000ff;">&#34;txtStepping&#34;</span><span style="color:#0000ff;">/&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 40:         <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">Button</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Column</span>=<span style="color:#0000ff;">&#34;0&#34;</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">Row</span>=<span style="color:#0000ff;">&#34;5&#34;</span> <span style="color:#ff0000;">Grid</span>.<span style="color:#ff0000;">ColumnSpan</span>=<span style="color:#0000ff;">&#34;2&#34;</span> <span style="color:#ff0000;">Width</span>=<span style="color:#0000ff;">&#34;75&#34;</span> <span style="color:#ff0000;">Margin</span>=<span style="color:#0000ff;">&#34;5&#34;</span> <span style="color:#ff0000;">Name</span>=<span style="color:#0000ff;">&#34;btnExit&#34;</span> <span style="color:#ff0000;">Click</span>=<span style="color:#0000ff;">&#34;btnExit_Click&#34;</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 41:             Exit
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 42:         <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">Button</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 43:     <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">Grid</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 44: <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">Window</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 45: </pre>
</pre>
<p>The C# code of this project is very easy. We just define the signature of our exported function and call them one by one. </p>
<pre style="border-bottom:#cecece 1px solid;border-left:#cecece 1px solid;background-color:#fbfbfb;min-height:40px;width:450px;overflow:auto;border-top:#cecece 1px solid;border-right:#cecece 1px solid;padding:5px;">
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  1: using System;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  2: using System.Collections.Generic;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  3: using System.Linq;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  4: using System.Text;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  5: using System.Windows;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  6: using System.Windows.Controls;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  7: using System.Windows.Data;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  8: using System.Windows.Documents;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  9: using System.Windows.Input;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 10: using System.Windows.Media;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 11: using System.Windows.Media.Imaging;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 12: using System.Windows.Navigation;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 13: using System.Windows.Shapes;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 14: using System.Runtime.InteropServices;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 15:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 16: namespace AsmWpf
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 17: {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 18:     /// <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">summary</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 19:     /// Interaction logic for Window1.xaml
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 20:     /// <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">summary</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 21:     public partial class Window1 : Window
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 22:     {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 23:         [DllImport(&#34;SysInfo.dll&#34;)]
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 24:         static extern int getCPUSpeed();
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 25:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 26:         [DllImport(&#34;SysInfo.dll&#34;)]
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 27:         static extern string getCPUType();
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 28:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 29:         [DllImport(&#34;SysInfo.dll&#34;)]
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 30:         static extern int getCPUFamily();
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 31:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 32:         [DllImport(&#34;SysInfo.dll&#34;)]
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 33:         static extern int getCPUModel();
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 34:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 35:         [DllImport(&#34;SysInfo.dll&#34;)]
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 36:         static extern int getCPUStepping();
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 37:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 38:         public Window1()
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 39:         {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 40:             InitializeComponent();
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 41:         }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 42:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 43:         private void Window_Loaded(object sender, RoutedEventArgs e)
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 44:         {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 45:             try
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 46:             {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 47:                 txtSpeed.Text = getCPUSpeed().ToString();
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 48:                 txtVendor.Text = getCPUType();
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 49:                 txtFamily.Text = getCPUFamily().ToString();
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 50:                 txtModel.Text = getCPUModel().ToString();
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 51:                 txtStepping.Text = getCPUStepping().ToString();
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 52:             }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 53:             catch (DllNotFoundException ex)
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 54:             {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 55:                 MessageBox.Show(ex.Message);
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 56:             }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 57:             catch (EntryPointNotFoundException ex)
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 58:             {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 59:                 MessageBox.Show(ex.Message);
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 60:             }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 61:         }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 62:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 63:         private void btnExit_Click(object sender, RoutedEventArgs e)
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 64:         {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 65:             Close();
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 66:         }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 67:     }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 68: }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 69: </pre>
</pre>
<p>Here is the output of this program.</p>
<p><a href="http://zamjad.files.wordpress.com/2009/11/asmwpf.gif"><img style="border-bottom:0;border-left:0;display:block;float:none;margin-left:auto;border-top:0;margin-right:auto;border-right:0;" title="AsmWpf" border="0" alt="AsmWpf" src="http://zamjad.files.wordpress.com/2009/11/asmwpf_thumb.gif?w=400&#038;h=300" width="400" height="300" /></a></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Calling Windows API from WPF Application]]></title>
<link>http://zamjad.wordpress.com/2009/11/09/calling-windows-api-from-wpf-application/</link>
<pubDate>Tue, 10 Nov 2009 04:25:46 +0000</pubDate>
<dc:creator>zamjad</dc:creator>
<guid>http://zamjad.wordpress.com/2009/11/09/calling-windows-api-from-wpf-application/</guid>
<description><![CDATA[Sometimes we want to access the low level functionality of operating system which is not directly av]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Sometimes we want to access the low level functionality of operating system which is not directly available in WPF. In that case we are going to call Windows API directly. Calling a Windows API from WPF program is similar to calling it from any console based .Net program. Let’s take a look at the example and calling two Windows API in our program to make non rectangular window. We are going to create a region with CreateRoundRectRgn and then set the current window region by calling SetWindowRgn. The only difference between calling API from Windows Form or any other .Net based program and WPF is that here we don’t have direct access to handle of window i.e. HWND. We have to use WindowInteropHelper class to get the handle of window. Here is a class diagram of WindowInteropHelper class.</p>
<p><a href="http://zamjad.files.wordpress.com/2009/11/wpfhwnd_02.gif"><img style="border-bottom:0;border-left:0;display:block;float:none;margin-left:auto;border-top:0;margin-right:auto;border-right:0;" title="WpfHwnd_02" border="0" alt="WpfHwnd_02" src="http://zamjad.files.wordpress.com/2009/11/wpfhwnd_02_thumb.gif?w=344&#038;h=201" width="344" height="201" /></a> </p>
<p>Here is a complete XAML code of this project.</p>
<pre style="border-bottom:#cecece 1px solid;border-left:#cecece 1px solid;background-color:#fbfbfb;min-height:40px;width:650px;overflow:auto;border-top:#cecece 1px solid;border-right:#cecece 1px solid;padding:5px;">
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  1: <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">Window</span> <span style="color:#ff0000;">x</span>:<span style="color:#ff0000;">Class</span>=<span style="color:#0000ff;">&#34;PInvokeWPF.Window1&#34;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  2:     <span style="color:#ff0000;">xmlns</span>=<span style="color:#0000ff;">&#34;http://schemas.microsoft.com/winfx/2006/xaml/presentation&#34;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  3:     <span style="color:#ff0000;">xmlns</span>:<span style="color:#ff0000;">x</span>=<span style="color:#0000ff;">&#34;http://schemas.microsoft.com/winfx/2006/xaml&#34;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  4:     <span style="color:#ff0000;">Title</span>=<span style="color:#0000ff;">&#34;PInvoke WPF&#34;</span> <span style="color:#ff0000;">Height</span>=<span style="color:#0000ff;">&#34;300&#34;</span> <span style="color:#ff0000;">Width</span>=<span style="color:#0000ff;">&#34;300&#34;</span> <span style="color:#ff0000;">Loaded</span>=<span style="color:#0000ff;">&#34;Window_Loaded&#34;</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  5:     <span style="color:#0000ff;">&#60;</span><span style="color:#800000;">Grid</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  6:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  7:     <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">Grid</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  8: <span style="color:#0000ff;">&#60;/</span><span style="color:#800000;">Window</span><span style="color:#0000ff;">&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  9: </pre>
</pre>
<p>Here is the complete C# code of the project.</p>
<pre style="border-bottom:#cecece 1px solid;border-left:#cecece 1px solid;background-color:#fbfbfb;min-height:40px;width:650px;overflow:auto;border-top:#cecece 1px solid;border-right:#cecece 1px solid;padding:5px;">
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  1: <span style="color:#0000ff;">using</span> System;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  2: <span style="color:#0000ff;">using</span> System.Collections.Generic;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  3: <span style="color:#0000ff;">using</span> System.Linq;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  4: <span style="color:#0000ff;">using</span> System.Text;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  5: <span style="color:#0000ff;">using</span> System.Windows;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  6: <span style="color:#0000ff;">using</span> System.Windows.Controls;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  7: <span style="color:#0000ff;">using</span> System.Windows.Data;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  8: <span style="color:#0000ff;">using</span> System.Windows.Documents;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;">  9: <span style="color:#0000ff;">using</span> System.Windows.Input;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 10: <span style="color:#0000ff;">using</span> System.Windows.Media;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 11: <span style="color:#0000ff;">using</span> System.Windows.Media.Imaging;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 12: <span style="color:#0000ff;">using</span> System.Windows.Navigation;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 13: <span style="color:#0000ff;">using</span> System.Windows.Shapes;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 14: <span style="color:#0000ff;">using</span> System.Runtime.InteropServices;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 15: <span style="color:#0000ff;">using</span> System.Windows.Interop;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 16:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 17: <span style="color:#0000ff;">namespace</span> PInvokeWPF
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 18: {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 19:     <span style="color:#808080;">/// &#60;summary&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 20:     <span style="color:#808080;">/// Interaction logic for Window1.xaml</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 21:     <span style="color:#808080;">/// &#60;/summary&#62;</span>
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 22:     <span style="color:#0000ff;">public</span> partial <span style="color:#0000ff;">class</span> Window1 : Window
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 23:     {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 24:         [DllImport(&#34;<span style="color:#8b0000;">user32.dll</span>&#34;)]
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 25:         <span style="color:#0000ff;">static</span> <span style="color:#0000ff;">extern</span> Int32 SetWindowRgn(IntPtr hWnd, IntPtr hRgn, <span style="color:#0000ff;">bool</span> bRedraw);
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 26:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 27:         [DllImport(&#34;<span style="color:#8b0000;">gdi32.dll</span>&#34;)]
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 28:         <span style="color:#0000ff;">static</span> <span style="color:#0000ff;">extern</span> IntPtr CreateRoundRectRgn(<span style="color:#0000ff;">int</span> x1, <span style="color:#0000ff;">int</span> y1, <span style="color:#0000ff;">int</span> x2, <span style="color:#0000ff;">int</span> y2, <span style="color:#0000ff;">int</span> cx, <span style="color:#0000ff;">int</span> cy);
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 29:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 30:         <span style="color:#0000ff;">public</span> Window1()
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 31:         {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 32:             InitializeComponent();
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 33:         }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 34:
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 35:         <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">void</span> Window_Loaded(<span style="color:#0000ff;">object</span> sender, RoutedEventArgs e)
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 36:         {
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 37:             IntPtr hwnd = <span style="color:#0000ff;">new</span> WindowInteropHelper(<span style="color:#0000ff;">this</span>).Handle;
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 38:             SetWindowRgn(hwnd, CreateRoundRectRgn(0, 0, 300, 300, 75, 75), <span style="color:#0000ff;">true</span>);
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 39:         }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 40:     }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 41: }
</pre>
<pre style="background-color:#fbfbfb;width:100%;font-family:consolas,&#39;font-size:12px;margin:0;"> 42: </pre>
</pre>
<p>Here is the output of this program. </p>
<p><a href="http://zamjad.files.wordpress.com/2009/11/pinvokewpf.gif"><img style="border-bottom:0;border-left:0;display:block;float:none;margin-left:auto;border-top:0;margin-right:auto;border-right:0;" title="PInvokeWPF" border="0" alt="PInvokeWPF" src="http://zamjad.files.wordpress.com/2009/11/pinvokewpf_thumb.gif?w=300&#038;h=300" width="300" height="300" /></a></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Calling WPF from VC++ Program]]></title>
<link>http://zamjad.wordpress.com/2009/11/01/calling-wpf-from-vc-program/</link>
<pubDate>Mon, 02 Nov 2009 04:46:45 +0000</pubDate>
<dc:creator>zamjad</dc:creator>
<guid>http://zamjad.wordpress.com/2009/11/01/calling-wpf-from-vc-program/</guid>
<description><![CDATA[Previously we saw that how can we call the Unmanaged dialog from WPF, now we are going to do the rev]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Previously we saw that how can we call the Unmanaged dialog from WPF, now we are going to do the reverse and calling the WPF from the win32 application. For calling WPF dialog, we have to compile our project with /CLR switch and include all the proper references of the required DLL. In addition we also include the proper namespaces in our VC++ program. Here is the simple VC++ program to call the WPF dialog. </p>
<pre style="border-right:#c0c0c0 1px solid;border-top:#c0c0c0 1px solid;min-height:40px;overflow:auto;border-left:#c0c0c0 1px solid;width:460px;border-bottom:#c0c0c0 1px solid;background-color:#fbfbfb;padding:5px;">
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;">  1: #include &#60;windows.h&#62;
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;">  2:
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;">  3: <span style="color:#0000ff;">using</span> <span style="color:#0000ff;">namespace</span> System;
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;">  4: <span style="color:#0000ff;">using</span> <span style="color:#0000ff;">namespace</span> System::Windows;
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;">  5:
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;">  6: [STAThread]
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;">  7: <span style="color:#0000ff;">int</span> WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;">  8: 				   LPSTR lpcStr, <span style="color:#0000ff;">int</span> nCmd)
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;">  9: {
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 10: 	Window^ win = gcnew Window();
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 11: 	win-&#62;Title = &#34;<span style="color:#8b0000;">WPF Window</span>&#34;;
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 12: 	win-&#62;Height = 300;
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 13: 	win-&#62;Width = 400;
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 14: 	win-&#62;Content = &#34;<span style="color:#8b0000;">This is WPF Window</span>&#34;;
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 15: 	win-&#62;ShowDialog();
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 16: 	<span style="color:#0000ff;">return</span> 0;
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 17: }
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 18: </pre>
</pre>
<p>Here is the output of this program. </p>
<p><a href="http://zamjad.files.wordpress.com/2009/11/wpfvc.gif"><img title="WPFVC" style="border-right:0;border-top:0;display:block;float:none;margin-left:auto;border-left:0;margin-right:auto;border-bottom:0;" height="300" alt="WPFVC" src="http://zamjad.files.wordpress.com/2009/11/wpfvc_thumb.gif?w=400&#038;h=300" width="400" border="0" /></a> </p>
<p>If we want to make our Win32 window as a parent of this window then we can’t directly set the handle of window as an owner of this window. We first have to create an object of WindowInteropHelper class and pass the WPF window as a parameter to the constructor and then use IntPtr to set the owner of the WPF window. These are defined in System::Windows::Interop namespace. Here is simple code to demonstrate this. </p>
<pre style="border-right:#c0c0c0 1px solid;border-top:#c0c0c0 1px solid;min-height:40px;overflow:auto;border-left:#c0c0c0 1px solid;width:460px;border-bottom:#c0c0c0 1px solid;background-color:#fbfbfb;padding:5px;">
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;">  1: Window^ win = gcnew Window();
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;">  2: Windows::Interop::WindowInteropHelper^ wih = gcnew Windows::Interop::WindowInteropHelper(win);
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;">  3: wih-&#62;Owner = IntPtr(hWnd);
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;">  4: </pre>
</pre>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[WPF Data Binding]]></title>
<link>http://devonethatdevelops.wordpress.com/2009/10/06/wpf-data-binding/</link>
<pubDate>Tue, 06 Oct 2009 08:08:29 +0000</pubDate>
<dc:creator>rubio67</dc:creator>
<guid>http://devonethatdevelops.wordpress.com/2009/10/06/wpf-data-binding/</guid>
<description><![CDATA[While the idea of Data Binding is excellent, there are some concepts that I have found hard to grasp]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>While the idea of Data Binding is excellent, there are some concepts that I have found hard to grasp. The first one is instantiating classes in XAML. Coming from procedural programming, I first assumed that a UI control&#8217;s property would be bound to an instance of a class.  Suppose you have a class called MyClass. To support change notification it has to    implement INotifyPropertyChange interface, which isn&#8217;t shown in the code below.</p>
<pre class="brush: csharp;">class MyClass
{
   private string color;

   public string Color
   {
      get { return this.color; }
      set { this.color = value; }
   }
}</pre>
<p>In procedural code (in this case C#) you would create an instance of this class.</p>
<pre class="brush: csharp;">MyClass myObject = new MyClass;</pre>
<p>To create an instance of the class in XAML you have to define a resource.</p>
<pre class="brush: cpp;">&#60;DockPanel.Resources&#62;
      &#60;MyClass x:Key=&#34;myObject&#34;/&#62;</pre>
<p>When loading this XAML code the runtime creates an instance of the class MyClass and myObject is a &#8220;reference&#8221; to the instance. The catch is that the object scope is not the same as with C#-instantiated object. In XAML you can access the object through myObject. The object is actually stored in a <em>resource collection</em> and if you want to access myObject in C#, or<em> code-behind</em> as it&#8217;s called, you have to call <strong>Application.FindResource</strong>.</p>
<pre class="brush: csharp;">MyClass md = (MyClass)this.FindResource(&#34;myObject&#34;);</pre>
<p>To bind a Button&#8217;s Background property to the MyClass.Color property, you have to define the source object and the path to the property. Source defines the instance of the class, and Path defines the property. Because elements inherit their parent element&#8217;s properties through attached property mechanism, you could also define a DataContext in the DockPanel.</p>
<pre class="brush: cpp;">&#60;DockPanel&#62;
   &#60;DockPanel.DataContext&#62;
      &#60;Binding Source=&#34;{StaticResource myObject}&#34;/&#62;
   &#60;/DockPanel.DataContext&#62;

   &#60;Button Background=&#34;{Binding Path=Color}&#34;&#62;
      A button
   &#60;/Button&#62;
&#60;/DockPanel&#62;</pre>
<p>This ties all bindings inside the DockPanel to myObject.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[WPF Data Binding to Native Business Layer]]></title>
<link>http://devonethatdevelops.wordpress.com/2009/10/06/wpf-data-binding-to-native-business-layer/</link>
<pubDate>Tue, 06 Oct 2009 07:53:11 +0000</pubDate>
<dc:creator>rubio67</dc:creator>
<guid>http://devonethatdevelops.wordpress.com/2009/10/06/wpf-data-binding-to-native-business-layer/</guid>
<description><![CDATA[I was given a task to develop a new WPF UI on top of a native business layer. This obviously require]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>I was given a task to develop a new WPF UI on top of a native business layer. This obviously required me to create managed classes that wrap the native business logic. One of the best things in .NET is <em>data binding</em>, but using it with native data types requires a bit of work. This and following articles show an example of how you can implement WPF data binding to native legacy code. Interop is a complex subject on its own, but I will focus on data binding issues. You need to be familiar with WPF data binding and <em>DependencyProperties</em>.</p>
<p><strong>Simple wrapper class</strong></p>
<p>Suppose you have a native class that has a public field. The class constructor initializes the value.</p>
<pre class="brush: cpp;">class NativeDataClass
{
   public:
   int SomeValue;

   NativeDataClass();
};

...

NativeDataClass::NativeDataClass()
{
   SomeValue = 42;
}</pre>
<p>Now, suppose you want to display the public field value in a WPF TextBox. First you need to create a managed wrapper for the native class. You could use COM interop or P/Invoke, but I&#8217;ll use C++/CLI.</p>
<pre class="brush: cpp;">public ref class ManagedWrapper
{
   private:
   NativeDataClass* _dataObject;

   public:
   ManagedWrapper()
   {
      _dataObject = new NativeDataClass();
   }

   ~ManagedWrapper()
   {
      delete _dataObject;
   }
};</pre>
<p>Since ref types (ie. managed types) may not contain native types, I&#8217;ll use a pointer instead. Data binding requires that the class exposes properties, so I&#8217;ll create one.</p>
<pre class="brush: cpp;">public ref class ManagedWrapper
{
...

   property int SomeValue
   {
      int get()
      {
         return _dataObject-&#62;SomeValue;
      }

      void set(int value)
      {
         if (_dataObject-&#62;SomeValue != value)
         {
            _dataObject-&#62;SomeValue = value;
         }
      }
   }
}</pre>
<p>This is basically all you need, but I want change notification, so that when the native field value changes, the UI changes as well. Also, I want to have a two-way binding, that is, if the TextBox value is changed, I want the new value to propagate to the native class. For this I need change notification. For this WPF has an interface called INotifyPropertyChanged, which requires a single event to be implemented. So the final wrapper looks like this.</p>
<pre class="brush: cpp;">public ref class ManagedWrapper : public INotifyPropertyChanged
{
   private:
   NativeDataClass* _dataObject;

   public:
   ManagedWrapper()
   {
      _dataObject = new NativeDataClass();
   }

   ~ManagedWrapper()
   {
      delete _dataObject;
   }

   virtual event PropertyChangedEventHandler^ PropertyChanged;

   property int SomeValue
   {
      int get()
      {
         return _dataObject-&#62;SomeValue;
      }

      void set(int value)
      {
         if (_dataObject-&#62;SomeValue != value)
         {
            _dataObject-&#62;SomeValue = value;
            OnPropertyChanged(&#34;SomeValue&#34;);
         }
      }
   }

   protected:
   void OnPropertyChanged(String^ info)
   {
      PropertyChanged(this, gcnew PropertyChangedEventArgs(info));
   }
};</pre>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Speaking on Container Solutions and Applications at Interop New York]]></title>
<link>http://loosebolts.wordpress.com/2009/09/18/speaking-on-container-solutions-and-applications-at-interop-new-york/</link>
<pubDate>Fri, 18 Sep 2009 14:26:00 +0000</pubDate>
<dc:creator>mmanos</dc:creator>
<guid>http://loosebolts.wordpress.com/2009/09/18/speaking-on-container-solutions-and-applications-at-interop-new-york/</guid>
<description><![CDATA[I have been invited to speak and chair a panel at Interop, New York (November 16-20, 2009) to give a]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>I have been invited to speak and chair a panel at <a href="http://www.interop.com/newyork/">Interop, New York (November 16-20, 2009)</a> to give a talk exploring the hype and reality surrounding Data Center based containers and Green IT in general.&#160;&#160; </p>
<p><a href="http://www.interop.com/newyork/"><img style="border-bottom:0;border-left:0;display:inline;border-top:0;border-right:0;" title="image" border="0" alt="image" src="http://loosebolts.files.wordpress.com/2009/09/image.png?w=133&#038;h=135" width="133" height="135" /></a> </p>
<p>The goal of the panel discussion will help data center managers evaluate and approach containers by understanding their economics, key considerations and real-life customer examples.&#160; It’s going to be a great conversation.&#160; If you are attending Interop this year I would love to see you there!</p>
<p>&#160;</p>
<p>\Mm</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Configuración IIS y DCOM  para importar / exportar a MSExcel mediante Interop]]></title>
<link>http://wecnet.wordpress.com/2009/09/11/configuracion-iis-y-dcom-para-importar-exportar-a-msexcel-mediante-interop/</link>
<pubDate>Fri, 11 Sep 2009 14:45:17 +0000</pubDate>
<dc:creator>Wec</dc:creator>
<guid>http://wecnet.wordpress.com/2009/09/11/configuracion-iis-y-dcom-para-importar-exportar-a-msexcel-mediante-interop/</guid>
<description><![CDATA[Vaya un título más largo para empezar a publicar. Este es un problema que me rondó por la cabeza dur]]></description>
<content:encoded><![CDATA[Vaya un título más largo para empezar a publicar. Este es un problema que me rondó por la cabeza dur]]></content:encoded>
</item>
<item>
<title><![CDATA[Excel 2010: Asynch XLL UDFs]]></title>
<link>http://devrandom1.wordpress.com/2009/09/08/excel-2010-asynch-xll-udfs/</link>
<pubDate>Tue, 08 Sep 2009 22:18:33 +0000</pubDate>
<dc:creator>devrandom1</dc:creator>
<guid>http://devrandom1.wordpress.com/2009/09/08/excel-2010-asynch-xll-udfs/</guid>
<description><![CDATA[The Excel team blogged about async xll udfs today. There is one other unique investment in the area ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>The Excel team blogged about <a href="http://blogs.msdn.com/excel/archive/2009/09/08/more-on-performance-improvements-in-excel-2010.aspx" target="_blank">async xll udfs</a> today.</p>
<blockquote><p>There is one other unique investment in the area of calculation that I want to briefly mention:Asynchronous XLL User-Defined Functions (Asynch XLL UDFs). The idea behind Asynch XLL UDFs is this: we know that some of our customers use XLL UDFs as a way to fetch data from external data servers. The CPU usage on the machine running Excel isn’t very heavy, but the server handling the request may take a while to return the requested data. If you have 100 of these functions in A1:A100 for example, you can be waiting quite a while for your workbook to calculate, because Excel processes those cells one at a time. Since the local machine isn’t doing any heavy CPU processing, with Excel 2010 we’ve enabled the functionality to send all 100 XLL UDFs calls at one time, allowing the backend servers to process the requests in parallel.</p></blockquote>
<p>IMO, this is a much-needed feature. In the past, you&#8217;d have to write an Excel RTD server to fetch the values asynchronously, even if the backend was returning static data (or an addin wrapping the RTD server).  This lead to PnL &#38; Risk workbooks containing formulae written by both the users and the development team; not an ideal support scenario. The async udfs should help reduce user dependence on the IT team as far as maintenance of the formulae is concerned.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Podr&scaron;ka za Oracle baze u Visual Studio Team Systemu]]></title>
<link>http://darkojo.net/2009/09/07/podrka-za-oracle-baze-u-visual-studio-team-systemu/</link>
<pubDate>Mon, 07 Sep 2009 16:23:22 +0000</pubDate>
<dc:creator>darkojo</dc:creator>
<guid>http://darkojo.net/2009/09/07/podrka-za-oracle-baze-u-visual-studio-team-systemu/</guid>
<description><![CDATA[Visual Studio Team Edition for Database Professionals je odličan alat koji inženjerima baza podatka ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><a href="http://msdn.microsoft.com/en-us/teamsystem/dd408380.aspx">Visual Studio Team Edition for Database Professionals</a> je odličan alat koji inženjerima baza podatka omogućava niz fensi stvari kao što su verzioniranje sheme, generiranje testnih podataka, refaktoriranje i drugo. Međutim pitanje koje nam je često bilo postavljano, a na koje nisam imao odgovor, je da li je Oracle baza podržana. Odgovor je bio da VSTS podržava proširivanje i da je pitanje vremena kada će se netko sjetiti i napraviti provider za Oracle. I eto, konačno je došlo to vrijeme. <a href="http://www.quest.com/">Quest Software</a>, proizvođač najpoznatijeg alata za upravljanje Oracle bazama (Toad) trenutno radi na implementaciji Oracle providera za VSTS. Projekt kodnog naziva “Team Fuze” trenutno je u beti, a trebao bi izaći skupa s Visual Studiom 2010.</p>
<p>Sve detalje možete pročitati na njihovoj stranici <a href="http://www.teamfuze.net">http://www.teamfuze.net</a> gdje možete i preuzeti provider.</p>
<p>Ili pogledajte odmah:</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:57ec89ca-0c87-4d88-a64b-8b75618d40d2" class="wlWriterEditableSmartContent">
<div><span style='text-align:center; display: block;'><object width='425' height='350'><param name='movie' value='http://www.youtube.com/v/hlKKb3XDxQU&#038;rel=1&#038;fs=1&#038;showsearch=0&#038;hd=0' /><param name='allowfullscreen' value='true' /><param name='wmode' value='transparent' /><embed src='http://www.youtube.com/v/hlKKb3XDxQU&#038;rel=1&#038;fs=1&#038;showsearch=0&#038;hd=0' type='application/x-shockwave-flash' allowfullscreen='true' width='425' height='350' wmode='transparent'></embed></object></span></div>
</div>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Call unmanaged Dialog box from WPF]]></title>
<link>http://zamjad.wordpress.com/2009/09/01/call-unmanaged-dialog-box-from-wpf/</link>
<pubDate>Wed, 02 Sep 2009 03:37:02 +0000</pubDate>
<dc:creator>zamjad</dc:creator>
<guid>http://zamjad.wordpress.com/2009/09/01/call-unmanaged-dialog-box-from-wpf/</guid>
<description><![CDATA[We can call the unmanaged code from the WPF. There is a namespace System.Windows.Interop define all ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>We can call the unmanaged code from the WPF. There is a namespace System.Windows.Interop define all the necessary classes and structure for this purpose. </p>
<p>If we are working in VC++ then we can easily mix managed and unmanaged code. First we have to create an object of WindowInteropHelper class and then get the handle of window i.e. HWND. Once we get the HWND then we can use it with unmanaged code. Here is a code to get the HWND within WPF.</p>
<pre style="border-right:#c0c0c0 1px solid;border-top:#c0c0c0 1px solid;min-height:40px;overflow:auto;border-left:#c0c0c0 1px solid;width:460px;border-bottom:#c0c0c0 1px solid;background-color:#fbfbfb;padding:5px;">
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;">  1: WindowInteropHelper^ helper = gcnew WindowInteropHelper(<span style="color:#0000ff;">this</span>);
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;">  2: HWND hwnd = (HWND)helper-&#62;Handle.ToPointer();
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;">  3: </pre>
</pre>
<p>Here is a sample code to demonstrate this. Here we create a simple WPF window and create one button inside it. When user press that button then it will popup one unmanaged dialog from it. </p>
<pre style="border-right:#c0c0c0 1px solid;border-top:#c0c0c0 1px solid;min-height:40px;overflow:auto;border-left:#c0c0c0 1px solid;width:460px;border-bottom:#c0c0c0 1px solid;background-color:#fbfbfb;padding:5px;">
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;">  1: #include &#60;windows.h&#62;
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;">  2: #include &#34;<span style="color:#8b0000;">resource.h</span>&#34;
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;">  3: <span style="color:#0000ff;">using</span> <span style="color:#0000ff;">namespace</span> System;
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;">  4: <span style="color:#0000ff;">using</span> <span style="color:#0000ff;">namespace</span> System::Windows;
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;">  5: <span style="color:#0000ff;">using</span> <span style="color:#0000ff;">namespace</span> System::Windows::Media;
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;">  6: <span style="color:#0000ff;">using</span> <span style="color:#0000ff;">namespace</span> System::Windows::Controls;
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;">  7: <span style="color:#0000ff;">using</span> <span style="color:#0000ff;">namespace</span> System::Windows::Interop;
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;">  8:
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;">  9: HINSTANCE gInst;
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 10: LRESULT CALLBACK MyDialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 11:
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 12: <span style="color:#0000ff;">public</span> ref <span style="color:#0000ff;">class</span> MyWindow : <span style="color:#0000ff;">public</span> Window
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 13: {
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 14: <span style="color:#0000ff;">public</span>:
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 15: 	MyWindow()
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 16: 	{
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 17: 		Title = &#34;<span style="color:#8b0000;">Unmanaged DialogBox Demo</span>&#34;;
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 18: 		Width = 400;
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 19: 		Height = 300;
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 20:
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 21: 		Grid^ grid = gcnew Grid();
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 22:
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 23: 		Windows::Controls::RowDefinition^ row = gcnew Windows::Controls::RowDefinition();
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 24: 		Windows::Controls::ColumnDefinition^ col = gcnew Windows::Controls::ColumnDefinition();
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 25:
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 26: 		Button^ btn = gcnew Button();
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 27: 		btn-&#62;Content = &#34;<span style="color:#8b0000;">Call Dialog</span>&#34;;
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 28: 		btn-&#62;Margin = Thickness(10);
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 29: 		btn-&#62;Click += gcnew RoutedEventHandler(<span style="color:#0000ff;">this</span>, &#38;MyWindow::OnButton);
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 30:
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 31: 		grid-&#62;SetRow(btn, 0);
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 32: 		grid-&#62;SetColumn(btn, 0);
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 33:
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 34: 		grid-&#62;RowDefinitions-&#62;Add(row);
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 35: 		grid-&#62;ColumnDefinitions-&#62;Add(col);
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 36:
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 37: 		Content = grid;
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 38:
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 39: 		grid-&#62;Children-&#62;Add(btn);
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 40: 	}
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 41:
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 42: 	<span style="color:#0000ff;">void</span> OnButton(Object^ sender, RoutedEventArgs^ e)
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 43: 	{
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 44: 		WindowInteropHelper^ helper = gcnew WindowInteropHelper(<span style="color:#0000ff;">this</span>);
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 45: 		HWND hwnd = (HWND)helper-&#62;Handle.ToPointer();
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 46: 		DialogBox(gInst, MAKEINTRESOURCE(IDC_DIALOG), hwnd, (DLGPROC)MyDialogProc);
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 47: 	}
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 48: };
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 49:
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 50: LRESULT CALLBACK MyDialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 51: {
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 52: 	<span style="color:#0000ff;">switch</span>(uMsg)
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 53: 	{
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 54: 	<span style="color:#0000ff;">case</span> WM_COMMAND:
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 55: 		<span style="color:#0000ff;">switch</span>(LOWORD(wParam))
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 56: 		{
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 57: 			<span style="color:#0000ff;">case</span> IDC_CLOSE:
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 58: 				EndDialog(hWnd, LOWORD(lParam));
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 59: 				<span style="color:#0000ff;">break</span>;
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 60: 		}
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 61: 	}
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 62:
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 63: 	<span style="color:#0000ff;">return</span> FALSE;
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 64: }
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 65:
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 66: [STAThread]
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 67: <span style="color:#0000ff;">int</span> WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 68: 				   LPSTR lpCmd, <span style="color:#0000ff;">int</span> nCmd)
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 69: {
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 70: 	gInst = hInstance;
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 71:
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 72: 	MyWindow^ win = gcnew MyWindow();
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 73:
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 74: 	Application^ app = gcnew Application();
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 75: 	app-&#62;Run(win);
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 76: }
</pre>
<pre style="font-size:11px;width:100%;font-family:consolas,&#39;background-color:#fbfbfb;margin:0;"> 77: </pre>
</pre>
<p>Here is the output of the program.</p>
<p><a href="http://zamjad.files.wordpress.com/2009/09/vcwpfunmanaged_01.gif"><img title="vcwpfUnmanaged_01" style="border-right:0;border-top:0;display:block;float:none;margin-left:auto;border-left:0;margin-right:auto;border-bottom:0;" height="300" alt="vcwpfUnmanaged_01" src="http://zamjad.files.wordpress.com/2009/09/vcwpfunmanaged_01_thumb.gif?w=400&#038;h=300" width="400" border="0" /></a> </p>
<p>When user press this button then one dialog box will popup. Here is the output of it.</p>
<p><a href="http://zamjad.files.wordpress.com/2009/09/vcwpfunmanaged_02.gif"><img title="vcwpfUnmanaged_02" style="border-right:0;border-top:0;display:block;float:none;margin-left:auto;border-left:0;margin-right:auto;border-bottom:0;" height="300" alt="vcwpfUnmanaged_02" src="http://zamjad.files.wordpress.com/2009/09/vcwpfunmanaged_02_thumb.gif?w=400&#038;h=300" width="400" border="0" /></a></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[The importance of Interop Mumbai ]]></title>
<link>http://betweenthebytes.wordpress.com/2009/09/01/the-importance-of-interop-mumbai/</link>
<pubDate>Tue, 01 Sep 2009 11:14:08 +0000</pubDate>
<dc:creator>TechTrailer</dc:creator>
<guid>http://betweenthebytes.wordpress.com/2009/09/01/the-importance-of-interop-mumbai/</guid>
<description><![CDATA[When the first edition of the television show Indian Idol was nearing its conclusion in early 2005, ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>When the first edition of the television show <em>Indian Idol </em>was nearing its conclusion in early 2005, I remember one of the judges admitting to initial apprehension and expressing relief that the participating singers hadn’t let India down and had ensured that the show was as good as, or even better than, the forerunning British and American versions that it was modeled on.</p>
<p>When I set out a few months ago as Conference Chair to devise the conference program for <a title="Interop, the world's leading business technology event comes to India " href="http://www.interop.com/mumbai" target="_blank">Interop Mumbai 2009</a>, I had similar apprehensions. Where would we find so many speakers? Would the speakers be good enough? What about the workshops and demos? Would we be able to put together and deliver a conference and exposition of this scale in Mumbai? (a city notorious for its woeful lack of world-class convention infrastructure).<!--more--></p>
<p>After all, the Interop brand has huge equity and a legacy that goes back to the time when TCP/IP was still being perfected and the fledgling Internet was just about spreading into the realm of business. That’s way beyond what any TV reality show can ever hope to claim. To get a sense of the Interop heritage, let me quote from <em>A Brief History of the Internet </em>(Barry Leiner, Vinton Cerf, et al): “…Dan Lynch [one of the TCP/IP and Arpanet pioneers] in cooperation with the IAB arranged to hold a three day workshop for ALL vendors to come learn about how TCP/IP worked and what it still could not do well… After two years of conferences, tutorials, design meetings and workshops, a special event was organized that invited those vendors whose products ran TCP/IP well enough to come together in one room for three days to show off how well they all worked together and also ran over the Internet. <strong>In September of 1988 the first Interop trade show was born</strong>. 50 companies made the cut. 5,000 engineers from potential customer organizations came to see if it all did work as was promised. It did. Why? Because the vendors worked extremely hard to ensure that everyone’s products interoperated with all of the other products—even with those of their competitors. The Interop trade show has grown immensely since then and today it is held in [several] locations around the world each year to an audience of over 250,000 people who come to learn which products work with each other in a seamless manner, learn about the latest products, and discuss the latest technology.”</p>
<p>Over the years, as interoperability became less and less of an intractable problem, Interop evolved into a more broad-based business technology event. Now, 21 years on, after Las Vegas, New York, Tokyo, Sao Paulo and Moscow, Interop has finally arrived here in India and I am pretty confident that Interop Mumbai (7-9 Oct 2009) will be everything that everyone has come to expect from the leading business technology event worldwide.</p>
<p>We have over 60 speakers from all over the world spread across 20-plus sessions, six keynotes, three plenary panel discussions, and several workshops and special sessions, in four parallel tracks. My approach has been to provide a mix of subject experts, experienced practitioners, distinguished analysts, tech gurus and promising young enterprise-IT professionals from India. To give a realistic practical dimension to the conference, most of the sessions will be chaired by leading CIOs from various industry verticals. The icing on the cake is the large exhibit floor adjoining the conference halls, where delegates and visitors can see the latest technologies being showcased and demonstrated by close to 50 leading vendors, all in one place.</p>
<p>India is at a critical juncture in its quest to achieve “developed country” status, and I firmly believe that prudent deployment of Information Technology is one of the important factors that will help us get there quicker. I am further convinced that events such as Interop serve as enablers and triggers for enterprise IT managers, aiding them in making sound decisions for rapid and effective deployment of IT solutions in their organizations.</p>
<p>As the date for the event approaches, the excitement is palpable, and inexorably rising to a crescendo. Interop Mumbai 2009 will definitely be a landmark event in the annals of the evolution of enterprise-IT in India. Do join me on October 7th at the Bombay Exhibition Centre—<em>and be a witness to history in the making!</em></p>
<p><em>- </em><strong>Val Souza</strong></p>
<p><em>Conference Chair, Interop Mumbai 2009</em></p>
<p><em> (valsouza at ubmindia dot com)</em></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Creating COM Interop Assemblies with .NET 2.0]]></title>
<link>http://kenkopczyk.com/2009/08/18/net-com-and-interop-assemblies/</link>
<pubDate>Wed, 19 Aug 2009 03:14:11 +0000</pubDate>
<dc:creator>Ken</dc:creator>
<guid>http://kenkopczyk.com/2009/08/18/net-com-and-interop-assemblies/</guid>
<description><![CDATA[If you work with .NET long enough, sooner or later you&#8217;ll probably need to leverage older Win3]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>If you work with .NET long enough, sooner or later you&#8217;ll probably need to leverage older Win32 COM components.  To allow the CLR managed code of .NET to communicate with the unmanaged code of COM, a &#8220;middleman&#8221; in the form of an interop assembly must be created.  This can be done via Visual Studio or the Type Library Importer.</p>
<p><b>Creating an interop assembly with Visual Studio</b><br />
Enter the &#8220;Add reference&#8221; dialog of your project, browse for your registered COM server and select it.  Now take a look at the properties of the newly created reference.  It is actually pointing to a new assembly called Interop.COMServerName.dll:  If your COM server is foo.dll, the resulting assembly is called Interop.foo.dll.  You will find this assembly in your bin directory after you build.</p>
<p>If your project uses an .snk or .pfx for strong naming, the interop assembly will also be strong named using that file.</p>
<p>A major limitation of this method I found was the fact that you can&#8217;t change the version number of the interop assembly.  It is <i>always</i> 1.0.0.0.  Bummer.</p>
<p><b>Creating an interop assembly with Type Library Importer</b><br />
If you need more control, then you should use the <a href="http://msdn.microsoft.com/en-us/library/tt0cf3sx(VS.80).aspx">Type Library Importer (tlbimp)</a>.  This application is included with the .NET SDK.</p>
<p>Running the following command will create an interop assembly with a version number of your choosing:<br />
Using our foo.dll example:</p>
<pre class="brush: bash;">
tlbimp foo.dll /out:Interop.foo.dll /asmversion:2.0.0.0
</pre>
<p>If you need the interop assembly strongly named, you can do that also.  If you are using an .snk, use the following:</p>
<pre class="brush: bash;">
tlbimp foo.dll /out:Interop.foo.dll /asmversion:2.0.0.0 /keyfile:MyKey.snk
</pre>
<p>If you are using a .pfx for strong naming, it&#8217;s a bit trickier.  You will also need to leverage the <a href="http://msdn.microsoft.com/en-us/library/k5b5tt23(VS.80).aspx">Strong Name Tool (sn)</a> to create a keycontainer:</p>
<pre class="brush: bash;">
echo Prompts you for .pfx password
sn -i MyKey.pfx KeyContainerName

tlbimp foo.dll /out:Interop.foo.dll /asmversion:2.0.0.0 /keycontainer:KeyContainerName

echo Housecleaning.  Removes the key container from memory.
sn -d KeyContainerName
</pre>
<p>Now add it as a reference and you&#8217;re good to go!</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Windows 7 API Code Pack v1.0 released]]></title>
<link>http://codesmart.wordpress.com/2009/08/10/windows-7-api-code-pack-v1-0-released/</link>
<pubDate>Mon, 10 Aug 2009 01:15:23 +0000</pubDate>
<dc:creator>daggmano</dc:creator>
<guid>http://codesmart.wordpress.com/2009/08/10/windows-7-api-code-pack-v1-0-released/</guid>
<description><![CDATA[My new best friend, the Windows 7 Code Pack, has been released.  From Charlie Calvert&#8217;s Commun]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>My new best friend, the Windows 7 Code Pack, has been released.  From <a href="http://blogs.msdn.com/charlie/archive/2009/08/07/windows-7-code-pack-v-1-0-released.aspx">Charlie Calvert&#8217;s Community Blog</a>:</p>
<blockquote><p>The <strong>Windows® API Code Pack for Microsoft® .NET Framework</strong> provides  support for various features of Windows 7 and previous releases of that  operating system. The Code Pack has  reached version 1.0 and has been published  on Code Gallery:</p>
<ul>
<li><a href="http://code.msdn.microsoft.com/WindowsAPICodePack/Release/ProjectReleases.aspx?ReleaseId=3077">Download  it</a></li>
<li><a href="http://code.msdn.microsoft.com/WindowsAPICodePack">Read about  it</a></li>
<li><a href="http://code.msdn.microsoft.com/WindowsAPICodePack/Thread/List.aspx">Discuss  it</a></li>
<li><a href="http://code.msdn.microsoft.com/WindowsAPICodePack/WorkItem/List.aspx">Report  bugs</a></li>
</ul>
<p>Here are some of the features you can from managed code using the Code  Pack:</p>
<ul>
<li>Windows 7 Taskbar Jump Lists, Icon Overlay, Progress Bar, Tabbed Thumbnails,  and Thumbnail Toolbars.</li>
<li>Windows 7 Libraries, Known Folders, non-file system containers.</li>
<li>Windows Shell Search API support, a hierarchy of Shell Namespace entities,  and Drag and Drop functionality for Shell Objects.</li>
<li>Explorer Browser Control.</li>
<li>Shell property system.</li>
<li>Windows Vista and Windows 7 Common File Dialogs, including custom controls.</li>
<li>Windows Vista and Windows 7 Task Dialogs.</li>
<li>Direct3D 11.0, Direct3D 10.1/10.0, DXGI 1.0/1.1, Direct2D 1.0, DirectWrite,  Windows Imaging Component (WIC) APIs. (DirectWrite and WIC have partial support)</li>
<li>Sensor Platform APIs</li>
<li>Extended Linguistic Services APIs</li>
<li>Power Management APIs</li>
<li>Application Restart and Recovery APIs</li>
<li>Network List Manager APIs</li>
<li>Command Link control and System defined Shell icons.</li>
</ul>
</blockquote>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Brastel in the events]]></title>
<link>http://brastelcreative.wordpress.com/2009/08/05/brastels-events/</link>
<pubDate>Wed, 05 Aug 2009 12:28:50 +0000</pubDate>
<dc:creator>designbrastel</dc:creator>
<guid>http://brastelcreative.wordpress.com/2009/08/05/brastels-events/</guid>
<description><![CDATA[]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><img class="aligncenter size-full wp-image-543" title="event_brastel" src="http://brastelcreative.wordpress.com/files/2009/08/event_brastel.jpg" alt="event_brastel" width="480" height="494" /></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Selected Interop Improvement: How to Fill PPT AutoShapes]]></title>
<link>http://blog.thebehrens.net/2009/07/21/selected-interop-improvement-how-to-fill-ppt-autoshapes/</link>
<pubDate>Tue, 21 Jul 2009 12:09:48 +0000</pubDate>
<dc:creator>thorstenb</dc:creator>
<guid>http://blog.thebehrens.net/2009/07/21/selected-interop-improvement-how-to-fill-ppt-autoshapes/</guid>
<description><![CDATA[Part of ooo-build since early June, and now on the way to 3.2 for vanilla. Just a few pictures that ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>
Part of ooo-build since early June, and now on the way to 3.2 for vanilla. Just a few pictures that should tell the story, starting with the state of affairs up to and including OOo 3.1:
</p>
<p>
<a href="http://thorstenb.wordpress.com/files/2009/06/blog-sample-0-ooold.png"><img src="http://thorstenb.wordpress.com/files/2009/06/blog-sample-0-ooold.png?w=150" alt="blog-sample-0-ooold" title="vanilla OOo" width="150" height="116" class="aligncenter size-thumbnail wp-image-211" /></a>
</p>
<p>
The competition:
</p>
<p>
<a href="http://thorstenb.wordpress.com/files/2009/06/blog-sample-0.png"><img src="http://thorstenb.wordpress.com/files/2009/06/blog-sample-0.png?w=150" alt="blog-sample-0" title="PowerPoint" width="150" height="114" class="aligncenter size-thumbnail wp-image-213" /></a>
</p>
<p>
After the fix:
</p>
<p>
<a href="http://thorstenb.wordpress.com/files/2009/06/blog-sample-0-ooo.png"><img src="http://thorstenb.wordpress.com/files/2009/06/blog-sample-0-ooo.png?w=150" alt="blog-sample-0-ooo" title="The fixed OOo" width="150" height="113" class="aligncenter size-thumbnail wp-image-212" /></a>
</p>
<p>
The differences are a bit subtle when looked at on this scale, but quite annoying when encountered by someone who <em>designs</em> her presentations with an eye for details. Especially the way sub-shapes were gradient-filled before, like the top end of the can or the eyes of the smiley. Kudos to <a href="http://haumacher.blogspot.com/2005/08/svg-import-for-openofficeorg-20.html">haui</a> btw. for the very nice hack to make OOo believe a sub-shape actually has the same bounding box as the main shape. <a href="http://cgit.freedesktop.org/ooo-build/ooo-build/tree/patches/dev300/ppt-customshape-shading-fix.diff">Here&#8217;s</a> the patch for those interested in the gory details.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Referential Identity and Internship]]></title>
<link>http://smellegantcode.wordpress.com/2009/06/30/referential-identity-and-internship/</link>
<pubDate>Tue, 30 Jun 2009 11:37:02 +0000</pubDate>
<dc:creator>earwicker</dc:creator>
<guid>http://smellegantcode.wordpress.com/2009/06/30/referential-identity-and-internship/</guid>
<description><![CDATA[I was thinking about a gotcha in Java, and started wondering about the idea of making it convenient ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>I was thinking about <a href="http://stackoverflow.com/questions/1046068/would-one-have-to-know-the-machine-architecture-to-write-code/1046209#1046209">a gotcha in Java</a>, and started wondering about the idea of making it convenient to intern reference objects.</p>
<p>&#8220;Interning&#8221; refers to the idea of ensuring that there is only one instance of an object with a given internal configuration &#8211; the classic example being strings in Java and .NET. When you construct a new string from a string literal, code is inserted to ensure that you get back a reference to the same string object for any given string literal value. So if you have the quoted string <code>"Hello, world"</code> in two places in your source code, they will point to the same object. This is a form of referential identity.</p>
<p>This predictably causes confusion in Java because learners are duped into thinking that they will be able to compare string values with <code>==</code>, but this is not generally true, because other operations that create strings (such as concatenation, or reading from a file) do not take part in interning. It&#8217;s not such a problem in C# because you can implement a special version of <code>==</code> that compares the actual values instead of references, and this is exactly what the built-in <code>System.String</code> type does.</p>
<p>But then there are types that frequently occur in C# programs where you don&#8217;t have the ability to override the <code>==</code> operator. An example is an <code>interface </code>type &#8211; no overloading of operators is allowed with them. In the code I&#8217;m working on, a lot of things are described by COM interfaces, which look just like interfaces. I&#8217;d frequently like to be able to intern references to such things, allowing me to casually compare two references in a meaningful way. Especially where I&#8217;m dealing with an external COM library that just allocates objects on the fly to represent data, and so the identity of the object is not currently being put to good use &#8211; it&#8217;s completely meaningless.</p>
<p>But the right way to do this depends on some detail of the interface. There is also the question of the scope in which internship should apply &#8211; a whole process, or just the current thread?</p>
<p>Trivial example:</p>
<pre class="brush: csharp;">
public interface IMyWeirdInterface
{
    string Name { get;}
}
</pre>
<p>What I&#8217;d like is to be able to assume that any two objects of that type will be the same instance if they have the same <code>Name</code>. So what I need is an object that manages the &#8220;internship&#8221; in that way:</p>
<pre class="brush: csharp;">
var i = new Internship&lt;IMyWeirdInterface, string&gt;(m =&gt; m.Name);

IMyWeirdInterface x = new MockMyWeirdInterface { Name = &quot;Fred&quot; };
IMyWeirdInterface y = new MockMyWeirdInterface { Name = &quot;Fred&quot; };
IMyWeirdInterface z = new MockMyWeirdInterface { Name = &quot;Jim&quot; };

i.Intern(ref x);
i.Intern(ref y);
i.Intern(ref z);

Debug.Assert(x == y);
Debug.Assert(x != y);
</pre>
<p>So no matter from where a method obtains some references to <code>IMyWeirdInterface</code>, it can intern them and they will have referential identity. It just needs access to the right <code>Internship</code> object to manage this. With most COM objects, they are &#8220;apartment threadsafe&#8221;, which is a coy way of saying that they aren&#8217;t particularly threadsafe at all and should not be shared between threads. So for such objects, the right thing to do is make the <code>Internship</code> object <em>thread local</em>:</p>
<pre class="brush: csharp;">
public static class Internships
{
    [ThreadStatic] private static Internship&lt;IMyWeirdInterface, string&gt; WeirdThreadLocal;

    public static Internship&lt;IMyWeirdInterface, string&gt; Weird
    {
        get
        {
            if (WeirdThreadLocal == null)
                WeirdThreadLocal = new Internship&lt;IMyWeirdInterface, string&gt;(m =&gt; m.Name);

            return WeirdThreadLocal;
        }
    }
}
</pre>
<p>As well as being absolutely necessary to ensure objects don&#8217;t get mysteriously shared between threads, this also has the nice quality of avoiding the need for locks to coordinate between threads &#8211; it&#8217;s a per-thread singleton. Now, any method can say:</p>
<pre class="brush: csharp;">
Internships.Weird.Intern(ref x);
Internships.Weird.Intern(ref y);
</pre>
<p>And know that if <code>x</code> and <code>y</code> have the same <code>Name</code>, they will now be the same object.</p>
<p>Here&#8217;s the declaration of <code>Internship</code> (not exactly rocket science, is it?):</p>
<pre class="brush: csharp;">
public class Internship&lt;TRef, TKey&gt;
{
    private readonly Dictionary&lt;TKey, TRef&gt; _map = new Dictionary&lt;TKey, TRef&gt;();
    private readonly Func&lt;TRef, TKey&gt; _keySelector;

    public Internship(Func&lt;TRef, TKey&gt; keySelector)
    {
        _keySelector = keySelector;
    }

    public void Intern(ref TRef obj)
    {
        TKey key = _keySelector(obj);
        TRef result;
        if (_map.TryGetValue(key, out result))
            obj = result;
        else
            _map.Add(key, obj);
    }
}
</pre>
<p>The <code>keySelector</code> parameter to the constructor is the thing that controls how intances can be treated as identical, by picking a key value from a property (the Name property in my examples above).</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[C/AL++]]></title>
<link>http://xosfaere.wordpress.com/2009/06/30/navision-lazy-evaluation/</link>
<pubDate>Tue, 30 Jun 2009 05:43:32 +0000</pubDate>
<dc:creator>xosfaere</dc:creator>
<guid>http://xosfaere.wordpress.com/2009/06/30/navision-lazy-evaluation/</guid>
<description><![CDATA[Navision C/AL can be quite monotonous to develop in &#8211; which is also one of its strengths ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Navision <strong>C/AL</strong> can be quite monotonous to develop in &#8211; which is also one of its strengths &#8211; strength through simplicity, but sometimes one simply desires some power tools to get past the endless repetitive boiler-plate code.</p>
<p><strong>Microsoft .Net Framework, CLR, COM interop, C# and Lazy Evaluation (aka IEnumerable of T) to the rescue!</strong></p>
<p>The example I&#8217;ll show here is probably not the best one. I&#8217;ll be showing how to lazily enumerate files on the file system. Navision already has a special virtual table called the file table that serves to enumerate over the file system. Nevertheless, this example will show what you can do, and maybe you&#8217;ll prefer my approach, although minimizing dependencies on automations is of course desirable.</p>
<p>So, let&#8217;s get started here.</p>
<p>First we define an Navision version of the <strong>IEnumerable </strong>interface. This is straight-forward and is immensely useful for iteroperability between Navision and automations. It provides a very smooth iteration idiom.</p>
<p><code> </code></p>
<p><code></p>
<blockquote>
<pre>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Demo.IO
{
    using System.Runtime.InteropServices;

    [Guid("0BC2788B-A22E-4DF4-A04F-161E3A9EAFC4")]
    [ComVisible(true)]
    public interface ILinear
    {
        object Current { get; }

        bool MoveNext();

        void Reset();
    }
}</pre>
</blockquote>
<p></code></p>
<p>This simple interface provides a great deal of expressiveness due to its simplicity, generality and broad applicability.</p>
<p>In order to make use of this, an equal implementation class should be defined, it merely wraps around an IEnumerable&#60;object&#62;. This is left as an exercise for the reader.</p>
<p>Why IEnumerable of object you may ask? Because COM interop is not so happy about parametric polymorphism and generic types. That wohn&#8217;t be a problem in Navision though. The only problem is the limits around passing data to and from Navision where f.x. text is limited to 1024 characters. &#8211; But here you can again utilize the above type to indirectly pass around a large string wrapped in an ILinear.</p>
<p>Lazy Evaluation in C# 2.0 (yes, it&#8217;s so yesterday, but laziness never expires!) is our means to efficiently enumerate and traverse arbitrarily large file system trees. Here&#8217;s how it&#8217;s done.</p>
<p><code> </code></p>
<p><code></p>
<pre>        public ILinear GetFiles(string path, string pattern, bool recursive)
        {
            var result = (Linear)null;
            try
            {
                result = new Linear(LazyGetFiles(path, pattern, recursive));
            }
            catch (Exception) { }
            return result;
        }</pre>
<p></code></p>
<p>I&#8217;ll not show the definition of LazyGetFiles here, but you can find the basic technique many places on the Web, e.g.</p>
<ul>
<li><a href="http://weblogs.asp.net/whaggard/archive/2004/08/15/214864.aspx">http://weblogs.asp.net/whaggard/archive/2004/08/15/214864.aspx</a></li>
<li><a href="http://weblogs.asp.net/podwysocki/archive/2009/03/18/functional-net-laziness-becomes-you.aspx">http://weblogs.asp.net/podwysocki/archive/2009/03/18/functional-net-laziness-becomes-you.aspx</a></li>
</ul>
<p>I always wrap COM entry-points with exception handling to avoid crashing Navision should anything fail (using the most general exception class here). I found it a good practice to do this, in combination with access to the current exception state of the class, for logging unexpected run-time exceptions inside Navision.</p>
<p>It&#8217;s a bit painful to declare variables in Navision (you have to go through UI menus to do this, it&#8217;s not possible in pure text &#8211; although that may change in future versions of Navision) &#8211; the point of which is to say that if it were a bit less painful, maybe even with type-inference, one might instead return a <a href="http://en.wikibooks.org/wiki/Haskell/Hierarchical_libraries/Maybe">Maybe</a> value but we can use <strong>ISCLEAR</strong> from within Navision to detect null-values and therefore see if a failure occurred.</p>
</div>]]></content:encoded>
</item>

</channel>
</rss>
