<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>deeptanshuv's WebLog</title><link>http://blogs.msdn.com/b/deeptanshuv/</link><description /><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>Five card stud, nothing wild, and the sky's the limit</title><link>http://blogs.msdn.com/b/deeptanshuv/archive/2006/08/08/691787.aspx</link><pubDate>Tue, 08 Aug 2006 07:04:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:691787</guid><dc:creator>deeptanshuv</dc:creator><slash:comments>6</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/deeptanshuv/rsscomments.aspx?WeblogPostID=691787</wfw:commentRss><comments>http://blogs.msdn.com/b/deeptanshuv/archive/2006/08/08/691787.aspx#comments</comments><description>&lt;P&gt;Aug 7 was my last working day at Microsoft.&amp;nbsp; I am on vacation now and will officially end my employment at MS on Aug 23.&amp;nbsp; This means that there won't be any more Visual Studio blogs from me, unless I write one influenced by separation pangs.&lt;/P&gt;
&lt;P&gt;It has been an interesting seven years.&amp;nbsp; Not all of it was good but there have been more positive experiences than otherwise and I consider myself lucky to have gotten the opportunity to have been here.&amp;nbsp; Meeting my wife here was the clear highlight of my stay.&amp;nbsp; Meeting Bill Gates was next.&amp;nbsp; Watching Steve Ballmer dance on Microsoft's 25th anniversary should probably count as the third.&lt;/P&gt;
&lt;P&gt;All the best to you all for debugging all your apps, and I hope Visual Studio continues to enable you to do so in a user-friendly and robust manner.&amp;nbsp; Let us face it, if your coding skills are anything like mine you spend 25% of your time in the editor and 75% in the debugger.&amp;nbsp; The AppWizard?&amp;nbsp; Nobody even cares about it unless it generates bad code :)&lt;/P&gt;
&lt;P&gt;The title of this blog?&amp;nbsp; A simple search should explain it.&amp;nbsp; (Hint: Picard)&lt;/P&gt;
&lt;P&gt;The next chapter of my life will be written&amp;nbsp;at the &lt;A href="http://mba.yale.edu/"&gt;Yale School of Management&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=691787" width="1" height="1"&gt;</description></item><item><title>End of an era for Tech humor columnists</title><link>http://blogs.msdn.com/b/deeptanshuv/archive/2006/06/16/634726.aspx</link><pubDate>Sat, 17 Jun 2006 01:42:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:634726</guid><dc:creator>deeptanshuv</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/deeptanshuv/rsscomments.aspx?WeblogPostID=634726</wfw:commentRss><comments>http://blogs.msdn.com/b/deeptanshuv/archive/2006/06/16/634726.aspx#comments</comments><description>&lt;P&gt;I have been reading several websites' coverage of Bill Gates' announcement to step down from the Chief Software Architect role in 2008.&amp;nbsp; Most have focused on its impact on Microsoft, the technology industry, Wall Street and global health care (which stands to gain from the Gates Foundation).&lt;/P&gt;
&lt;P&gt;But there is another segment for whom the world has changed significantly.&amp;nbsp; For years I have been reading tech humour websites making fun of Bill Gates and the realization must now be dawning that soon there will be little new material for them.&amp;nbsp; Yesterday someone at Slashdot forums pointed out that &lt;A href="http://slashdot.org/"&gt;Slashdot's&lt;/A&gt; 'Borg Bill' gif might now need to be replaced.&amp;nbsp; Without Bill, even the generic 'Microsoft jokes' would start lacking bite after a while, though Steve Ballmer still is well-known and colorful enough to sustain several Microsoft jokes on his own.&amp;nbsp; Still, the curtain has probably come down on articles such as '&lt;A href="http://www.theonion.com/content/node/29023"&gt;Evil Genius Gates Drops Windows 98 Into NYC Water Supply&lt;/A&gt;'&lt;/P&gt;
&lt;P&gt;Who will provide the fodder for new material?&amp;nbsp; Would Microsoft be able to retain its dominant position as the butt of technology jokes over the next decade?&amp;nbsp; Time will tell.&amp;nbsp; Here are some potential challengers:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Sergey Brin and Larry Page - still too young, raw&amp;nbsp;and well liked in the internet community.&amp;nbsp; May I say also lacking the 'presence' that attracts humorists, though this could change.&amp;nbsp;&lt;/LI&gt;
&lt;P&gt;&lt;/P&gt;
&lt;LI&gt;Larry Ellison - An excellent target for humorists thanks to his over the top persona.&amp;nbsp; Still, makes it difficult to tell whether some stories are humor or plain facts.&amp;nbsp; Probably peaked as a humor target with '&lt;A href="http://www.satirewire.com/news/0006/satire-ellison.shtml"&gt;Diplomas are for losers&lt;/A&gt;'.&lt;/LI&gt;
&lt;P&gt;&lt;/P&gt;
&lt;LI&gt;Scott McNealy - Plethora of 'dot-not' and 'look-out' jokes have been insufficient to attain a leadership position in the tech humor segment.&amp;nbsp; In the tech segment either, for that matter.&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;The situation looks grim for tech humor columnists.&amp;nbsp; But the great thing about this industry is its ability to throw up a winner from apparently nowhere.&amp;nbsp; There is no reason why some kid in some garage somewhere cannot rise to become the inspiration for all jokes in the days to come.&amp;nbsp; Heck, with a bit of effort and enterprise, it could even be you.&amp;nbsp; And needless to say, Microsoft will be around.&amp;nbsp; And we are still the only company with the resources to build a &lt;A href="http://www.bbspot.com/News/2002/05/deathstar.html"&gt;Death Star&lt;/A&gt;.&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=634726" width="1" height="1"&gt;</description></item><item><title>Code Center Premium integration into Visual Studio</title><link>http://blogs.msdn.com/b/deeptanshuv/archive/2006/06/13/630206.aspx</link><pubDate>Wed, 14 Jun 2006 03:16:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:630206</guid><dc:creator>deeptanshuv</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/deeptanshuv/rsscomments.aspx?WeblogPostID=630206</wfw:commentRss><comments>http://blogs.msdn.com/b/deeptanshuv/archive/2006/06/13/630206.aspx#comments</comments><description>&lt;P&gt;Microsoft provides source access to some customers via its &lt;A href="http://www.microsoft.com/resources/sharedsource/ccp/premium.mspx"&gt;Code Center Premium &lt;/A&gt;(CCP) program.&amp;nbsp; Not many people are aware that Visual Studio 2005 has integrated CCP support.&lt;/P&gt;
&lt;P&gt;It is true!&amp;nbsp; While debugging applications in VS you can download sources for system files from the code premium website provided you have CCP access.&amp;nbsp; The prompting for the CCP card pin is handled in-session.&amp;nbsp; The same license agreements apply.&lt;/P&gt;
&lt;P&gt;This link gives you complete instructions on how to go about enabling and using this with VS 2005 - &lt;A href="http://msdn2.microsoft.com/en-us/library/ms164729.aspx"&gt;http://msdn2.microsoft.com/en-us/library/ms164729.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Note that the CCP program is independent of Visual Studio and we are not involved in providing CCP source access.&amp;nbsp; If you are interested in the program or have any complaints accessing the files you would need to contact the CCP team - &lt;A href="http://www.microsoft.com/resources/sharedsource/ccp/premium.mspx"&gt;http://www.microsoft.com/resources/sharedsource/ccp/premium.mspx&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Regards,&lt;BR&gt;Deep&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=630206" width="1" height="1"&gt;</description></item><item><title>64-bit and Visual Studio 2005</title><link>http://blogs.msdn.com/b/deeptanshuv/archive/2006/04/11/573795.aspx</link><pubDate>Wed, 12 Apr 2006 03:18:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:573795</guid><dc:creator>deeptanshuv</dc:creator><slash:comments>7</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/deeptanshuv/rsscomments.aspx?WeblogPostID=573795</wfw:commentRss><comments>http://blogs.msdn.com/b/deeptanshuv/archive/2006/04/11/573795.aspx#comments</comments><description>&lt;P&gt;We keep receiving questions about Visual Studio 2005's support for 64-bit.&amp;nbsp; Here is a set of factoids that should help answer the most commonly enquired issues:&lt;/P&gt;
&lt;P&gt;(a) There are two flavours of 64-bit - AMD64 or X64, and IA64.&amp;nbsp; Windows 64-bit installs on both architectures.&lt;/P&gt;
&lt;P&gt;(b) There is no 64-bit version of VS. Visual Studio 2005 is available only as a 32-bit app.&amp;nbsp; However, you CAN install VS on a 64-bit OS and use it to create, launch and debug 64-bit apps.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;(c) VS will install only on X64.&amp;nbsp; The .Net Framework and the Debugger components install on IA64, allowing you to remotely launch and debug applications on IA64 from a VS IDE installed on another machine. &lt;/P&gt;
&lt;P&gt;(d) VS installed on either 32-bit or 64-bit OS can create 32-bit or 64-bit applications, but of course the applications need the corresponding platform to execute.&lt;/P&gt;
&lt;P&gt;(e) You need the Professional or Team System versions to build X64 (AMD64) apps.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;(f) You need Team System to build IA64 apps. Pro does not support this. See &lt;A href="http://msdn2.microsoft.com/en-us/library/hs24szh9(VS.80).aspx"&gt;http://msdn2.microsoft.com/en-us/library/hs24szh9(VS.80).aspx&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;(g) On a 32-bit OS, the 64-bit compilers will not be installed by default, you will need to go to custom setup and check the option.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;How to create 64-bit apps&lt;/U&gt;&lt;/STRONG&gt;&lt;BR&gt;&lt;/P&gt;
&lt;P&gt;A managed project is automatically built according to the architecture selected =&amp;gt; default C# project created on AMD64 will be AMD64, X86 on X86.&amp;nbsp; The native one is always 32-bit by default.&lt;/P&gt;
&lt;P&gt;To explicitly set a platform: &lt;/P&gt;
&lt;P&gt;(1) open the solution explorer, select solution, right click-&amp;gt;Configuration Manager. &lt;BR&gt;(2) go to 'Active Solution Platform', click New. &lt;BR&gt;(3) in the 'New Solution Platform' dialog that comes up select the new platform say Itanium. Set 'Copy Settings From' to 'Any CPU' which was the default setting in the 'Active Solution Platform'.&lt;BR&gt;(4) click OK.&lt;/P&gt;
&lt;P&gt;You will see that the platform has changed to Itanium in the config manager.&amp;nbsp; Now when you build the&amp;nbsp; solution, you will get an Itanium exe.&lt;/P&gt;
&lt;P&gt;Follow the same process for X64, and to rebuild 32-bit apps from that solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=573795" width="1" height="1"&gt;</description></item><item><title>Quality Milestone, Marriage, Star Trek and Pilchuck</title><link>http://blogs.msdn.com/b/deeptanshuv/archive/2006/02/23/538309.aspx</link><pubDate>Fri, 24 Feb 2006 03:54:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:538309</guid><dc:creator>deeptanshuv</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/deeptanshuv/rsscomments.aspx?WeblogPostID=538309</wfw:commentRss><comments>http://blogs.msdn.com/b/deeptanshuv/archive/2006/02/23/538309.aspx#comments</comments><description>&lt;P&gt;It has been a while since I blogged.&amp;nbsp; One reason is that not much is going on.&amp;nbsp; Of course, at Microsoft that is a deceptive statement.&amp;nbsp; By "not much" I mean that not much immediately impacting the customer is going on.&amp;nbsp; We released VS 2005 and are starting work on the next version; however, before doing so we decided to take a break and improve our processes and infrastructure to make for a smoother release cycle than we had for VS 2005.&amp;nbsp; A lot of dust that had gotten under the carpet is being cleaned, some processes and practices are getting discarded and new ones being brought in.&amp;nbsp; It is amazing how "inefficiency" creeps in slowly over time; only when you step back and start asking "why the hell do we do this?" do you realize the baggage you have accumulated.&lt;/P&gt;
&lt;P&gt;Additionally, I am getting married in March.&amp;nbsp; Now you know where I spent the time I would use earlier for blogs and newsgroups.&amp;nbsp; Given the time I used to hang out at the MS campus it is not overly surprising that my fiancee is also a Microsoftie.&amp;nbsp; I have gotten her interested in Star Trek: The Next Generation&amp;nbsp;and hope to also develop her interest in Warcraft.&amp;nbsp; In turn, she has cured me of my habit of spending weekends in the office.&lt;/P&gt;
&lt;P&gt;I went climbing Mt Pilchuck with some friends this weekend.&amp;nbsp; Just so you know, it is not an easy hike this time of year with all the snow.&amp;nbsp; Heck, it is not even an easy drive to get to the mountain.&amp;nbsp; A couple of cars got stuck in the snow and my friends and I helped push one poor guy's SUV out.&amp;nbsp; The fun part was that when the tires started rolling they sprayed snow all over &lt;A HREF="/richcook"&gt;Richard's&lt;/A&gt; trousers.&lt;/P&gt;
&lt;P&gt;Finally, I discovered "The Picard Song" in January.&amp;nbsp; Apparently it has been out since 2003 only nobody told me.&amp;nbsp; It is quite addictive and I would recommend that you give it a hearing: &lt;A href="http://thepicardsong.ytmnd.com/"&gt;http://thepicardsong.ytmnd.com/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Regards,&lt;BR&gt;Deep&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=538309" width="1" height="1"&gt;</description></item><item><title>Interop followup : handling C2065 errors building C++ Exe</title><link>http://blogs.msdn.com/b/deeptanshuv/archive/2005/12/28/507852.aspx</link><pubDate>Thu, 29 Dec 2005 01:07:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:507852</guid><dc:creator>deeptanshuv</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/deeptanshuv/rsscomments.aspx?WeblogPostID=507852</wfw:commentRss><comments>http://blogs.msdn.com/b/deeptanshuv/archive/2005/12/28/507852.aspx#comments</comments><description>&lt;P&gt;Hi!&lt;/P&gt;
&lt;P&gt;A customer emailed me with the feedback that my &lt;a href="http://blogs.msdn.com/deeptanshuv/archive/2005/06/26/432870.aspx"&gt;sample code with C++ Exe calling C# Dll &lt;/A&gt;does not build with VS 2003.&lt;/P&gt;
&lt;P&gt;I investigated; the reason is that in VS 2003 the tlb exposes the namespace in lowercase as csdll instead of CSDll. The fix for this is to update the C++ code to use 'csdll'.&lt;/P&gt;
&lt;P&gt;Alternately, you can add a 'no_namespace' to the #import tlb line in the .cpp file and then call all CSDll objects without using the namespace.&lt;/P&gt;
&lt;P&gt;Regards,&lt;BR&gt;D.V.&lt;BR&gt;&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=507852" width="1" height="1"&gt;</description></item><item><title>Debugger Chat Thursday Dec 15</title><link>http://blogs.msdn.com/b/deeptanshuv/archive/2005/12/13/503355.aspx</link><pubDate>Wed, 14 Dec 2005 01:58:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:503355</guid><dc:creator>deeptanshuv</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/deeptanshuv/rsscomments.aspx?WeblogPostID=503355</wfw:commentRss><comments>http://blogs.msdn.com/b/deeptanshuv/archive/2005/12/13/503355.aspx#comments</comments><description>&lt;P&gt;Hi!&lt;/P&gt;
&lt;P&gt;The Debugger team is having a Chat this Thursday (Dec 15)&amp;nbsp;from 1:00 to 2:00 Pacific Time. If you have any problems with the debugger, this would be a great opportunity to ask questions and get live responses. &lt;/P&gt;
&lt;P&gt;The Chat homepage is &lt;A href="http://msdn.microsoft.com/chats/"&gt;http://msdn.microsoft.com/chats/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;D.V.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=503355" width="1" height="1"&gt;</description></item><item><title>Visual Studio 2003 stops downloading symbols from the Microsoft public symbol server</title><link>http://blogs.msdn.com/b/deeptanshuv/archive/2005/10/10/479347.aspx</link><pubDate>Tue, 11 Oct 2005 00:51:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:479347</guid><dc:creator>deeptanshuv</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/deeptanshuv/rsscomments.aspx?WeblogPostID=479347</wfw:commentRss><comments>http://blogs.msdn.com/b/deeptanshuv/archive/2005/10/10/479347.aspx#comments</comments><description>&lt;P&gt;Hi!&lt;/P&gt;
&lt;P&gt;Recently, downloading symbols for microsoft shipped binaries using the&amp;nbsp;Microsoft symbol server (&lt;A href="http://msdl.microsoft.com/download/symbols"&gt;http://msdl.microsoft.com/download/symbols&lt;/A&gt;) broke for Visual Studio 2003&amp;nbsp;users. Microsoft has disabled downloading symbols using older versions of symsrv.dll for compatibility reasons.&lt;/P&gt;
&lt;P&gt;To resolve this, you need to update the symsrv.dll on your machine with a newer version. Symsrv.dll is a component that is updated periodically, and the latest version can be obtained from the debugging tools for windows package at &lt;A href="http://www.microsoft.com/whdc/devtools/debugging/default.mspx"&gt;http://www.microsoft.com/whdc/devtools/debugging/default.mspx&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;Simply replace your Visual Studio symsrv.dll (located next to devenv.exe) with the one from the debugging tools package, and everything should start working fine.&lt;/P&gt;
&lt;P&gt;Regards,&lt;BR&gt;D.V.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=479347" width="1" height="1"&gt;</description></item><item><title>Source checksums and breakpoints</title><link>http://blogs.msdn.com/b/deeptanshuv/archive/2005/07/24/442723.aspx</link><pubDate>Sun, 24 Jul 2005 22:14:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:442723</guid><dc:creator>deeptanshuv</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/deeptanshuv/rsscomments.aspx?WeblogPostID=442723</wfw:commentRss><comments>http://blogs.msdn.com/b/deeptanshuv/archive/2005/07/24/442723.aspx#comments</comments><description>&lt;P&gt;In VS 2003 &amp;amp; earlier breakpoints were bound based only on file name, so if the project system found another file with the same name we would bind the bp there. This was a source of a lot of annoyances since files like Class1.cs are everywhere, so in VS 2005 we have added support for source checksums in the compilers, and the debugger looks at these to verify a file.&lt;/P&gt;
&lt;P&gt;If we find the correct file, your debugging experience goes exactly as earlier, but some customers have had problems working with sources out of sync with the binaries they are debugging (people may want to try this if the exactly matching sources are inaccessible for some reason).&lt;/P&gt;
&lt;P&gt;If you start debugging with mismatching sources, you get a nice dialog informing you that the source is not matching, you can choose to continue to use it anyway. In this case, for the rest of the debugging session, you will not get prompted again, and if you set breakpoints in the file, they will bind.&lt;/P&gt;
&lt;P&gt;If you already had set breakpoints before starting to debug, those bp's may not bind. In that case, you can right click on the breakpoint, click the "Location" menu item, and in the&amp;nbsp; "File Breakpoint" dialog check the "Allow source code to be different from the original version" checkbox. Note that only file breakpoints are affected by checksums.&lt;/P&gt;
&lt;P&gt;Alternately, you can turn off verifying checksums altogether from &lt;EM&gt;Tools-&amp;gt;Options-&amp;gt;Debugging-&amp;gt;General-&amp;gt;Require source files to exactly match the original version&lt;/EM&gt;.&lt;BR&gt;&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=442723" width="1" height="1"&gt;</description></item><item><title>How to call C++ code from Managed, and vice versa (Interop)</title><link>http://blogs.msdn.com/b/deeptanshuv/archive/2005/06/26/432870.aspx</link><pubDate>Mon, 27 Jun 2005 00:39:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:432870</guid><dc:creator>deeptanshuv</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/deeptanshuv/rsscomments.aspx?WeblogPostID=432870</wfw:commentRss><comments>http://blogs.msdn.com/b/deeptanshuv/archive/2005/06/26/432870.aspx#comments</comments><description>&lt;P&gt;Interop - calling native (C++) code from managed (C#, VB, J#, MC++) and vice versa - can be very useful if you are trying to extend your libraries without porting existing code. However, it can often be confusing for a newbie to figure out how to set this up.&lt;/P&gt;
&lt;P&gt;There are several ways in which you could&amp;nbsp;accomplish this.&lt;/P&gt;
&lt;P&gt;(a) Using COM-Interop&lt;BR&gt;(b) Using imports/pinvoke (explicit method calls)&lt;BR&gt;(c) IJW and MC++ apps :&amp;nbsp;&amp;nbsp; MC++ &amp;amp; IJW apps can freely call back and forth to each other. &lt;BR&gt;(d) Hosting. This is rare, but the CLR can be hosted by an unmanaged app which means that the runtime invokes a bunch of hosting callbacks.&lt;/P&gt;
&lt;P&gt;Here is how (a) works:&lt;/P&gt;
&lt;P&gt;For Native Exe-&amp;gt;Managed Dll&lt;/P&gt;
&lt;P&gt;(a)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; define C# (VB, J#) class with a public interface, and build the file as dll&lt;BR&gt;(b)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; run regasm on the dll to create the tlb file&lt;BR&gt;(c)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; define C++ code which #imports the type library and creates the C# dll’s interface object using CoCreateInstance() and then calls methods through that.&lt;/P&gt;
&lt;P&gt;For managed client-&amp;gt;Native Dll&lt;/P&gt;
&lt;P&gt;(a)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create C++ Dll&lt;BR&gt;(b)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Create managed exe, add a reference to the Native COM Dll&lt;BR&gt;(c)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Create the Com object and call the methods.&lt;/P&gt;
&lt;P&gt;Here are code samples for the cases&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Native Exe calling Managed Dll&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Dll code is (filename CSDll.cs)&lt;/P&gt;
&lt;P&gt;using System;&lt;BR&gt;using System.Collections.Generic;&lt;BR&gt;using System.Text;&lt;BR&gt;namespace CSDll&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; using System;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [System.Runtime.InteropServices.Guid("D4660088-308E-49fb-AB1A-77224F3FF851")]&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public interface IMyManagedInterface&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int factorial(int arg);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /// &amp;lt;summary&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ///&amp;nbsp;&amp;nbsp;&amp;nbsp; Summary description for Class1.&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /// &amp;lt;/summary&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [System.Runtime.InteropServices.Guid("46A951AC-C2D9-48e0-97BE-91F3C9E7B065")]&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public class Class1 : IMyManagedInterface&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public Class1()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public int factorial(int arg)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int result;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (arg == 1)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; result = arg;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; result = arg * factorial(arg - 1);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return result;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;}&lt;BR&gt;&lt;/P&gt;
&lt;P&gt;Compile this with "&lt;STRONG&gt;csc /debug /t:library csdll.cs&lt;/STRONG&gt;" to build a dll with symbol info.&lt;BR&gt;Now run "&lt;STRONG&gt;regasm csdll.dll /tlb:csdll.tlb&lt;/STRONG&gt;" to create the type library&lt;/P&gt;
&lt;P&gt;C++ code is as (filename cppexe.cpp)&lt;/P&gt;
&lt;P&gt;#include "windows.h"&lt;BR&gt;#include &amp;lt;stdio.h&amp;gt;&lt;BR&gt;#import "CSDll.tlb" named_guids&lt;/P&gt;
&lt;P&gt;int main(int argc, char* argv[])&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;HRESULT hRes = S_OK;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CoInitialize(NULL);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CSDll::IMyManagedInterface *pManagedInterface = NULL;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;hRes = CoCreateInstance(CSDll::CLSID_Class1, NULL, CLSCTX_INPROC_SERVER,&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CSDll::IID_IMyManagedInterface, reinterpret_cast&amp;lt;void**&amp;gt; (&amp;amp;pManagedInterface));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (S_OK == hRes)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;long retVal =0;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;hRes = pManagedInterface-&amp;gt;raw_factorial(4, &amp;amp;retVal);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;printf("The value returned by the dll is %ld\n",retVal);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;pManagedInterface-&amp;gt;Release();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CoUninitialize();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return 0;&lt;BR&gt;}&lt;BR&gt;&lt;/P&gt;
&lt;P&gt;Build this with "&lt;STRONG&gt;cl /Zi cppexe.cpp&lt;/STRONG&gt;" -&amp;gt; when you run the exe it should print the value 24.&lt;/P&gt;
&lt;P&gt;To debug this app, open the exe as a project in Visual Studio. Then go to project-&amp;gt;properties-&amp;gt;configuration prop-&amp;gt;debugging and set debugger type to Mixed. Now when you debug, you should be able to step into the managed dll code from the calling C++ exe.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Managed Exe calling Native Dll&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;(a) Create an Atl COM Dll from wizard say Atl Dll&lt;BR&gt;(b) Add an ATL Simple Object AtlObj&lt;BR&gt;(c) Add a method to AtlObj say factorial(), you will need to add it to the .idl file to expose it from the COM object&lt;BR&gt;(d) Create a C# console app&lt;BR&gt;(e) project-&amp;gt;right click-&amp;gt;Add Reference&lt;BR&gt;(f) In the add reference dialog, select the COM tab, find your COM component and add the reference to it&lt;BR&gt;(g) You can now create the AtlObj object as of any other class and call its methods.&lt;/P&gt;
&lt;P&gt;You can also accomplish this without using COM by simply using exports/imports.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Managed Exe calling Native Dll using import&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;(a) Create a Win32 Dll that exports symbols, you can do this from the wizard, just make sure the "export symbols" checkbox is checked.&lt;BR&gt;(b) You need to put extern "C" {} around the definition &amp;amp; declaration of the exported function say fnWin32Dll()&lt;BR&gt;(b) Now create your C# Exe, add using System.Runtime.InteropServices;&lt;BR&gt;(c) add code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;[[DllImport("Win32 Dll.dll")]&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;public static extern int fnWin32Dll();&amp;nbsp;'&amp;nbsp;this is the C++ function exposed by the dll&lt;/P&gt;
&lt;P&gt;(d) Now you can just call the function in your code&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;int var = fnWin32Dll();&lt;/P&gt;
&lt;P&gt;Note that your C# Exe needs to be able to find the Dll. You can copy the Dll next to the C# Exe and it will run just fine.&lt;/P&gt;
&lt;P&gt;These are the most common ways of making cross-language calls,&amp;nbsp;I will follow up later with explanations and examples of the other ways you can make&amp;nbsp;these calls.&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=432870" width="1" height="1"&gt;</description></item></channel></rss>