<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Sharing Knowledge</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/varunsekhri/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/varunsekhri/feed.xml</link>
    <description />
    <lastBuildDate>Wed, 17 Apr 2019 03:42:55 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>iOS AudioSession categories, routes etc..</title>
      <link>https://docs.microsoft.com/archive/blogs/varunsekhri/ios-audiosession-categories-routes-etc</link>
      <pubDate>Wed, 21 Dec 2011 10:42:00 GMT</pubDate>
      <dc:creator><![CDATA[varuns]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/varunsekhri/2011/12/21/ios-audiosession-categories-routes-etc/</guid>
      <description><![CDATA[So you want to record/play something on iOS and now have to deal with AudioSession, categories,...]]></description>
      <content:encoded><![CDATA[<p>So you want to record/play something on iOS and now have to deal with AudioSession, categories, routing of audio&nbsp; etc. There is good documentation on apple website <a href="https://developer.apple.com/library/ios/#documentation/Audio/Conceptual/AudioSessionProgrammingGuide/Introduction/Introduction.html">here</a>. Information on that link&nbsp;can&nbsp;be very overwhelming for a first timer and then mistakes happen. &nbsp;</p>
<p>Here is a great lecture video which I found to be useful. WWDC 2010 session 412 Audio Development for iPhone OS part 1. You will need a developer account (which is free) with apple and iTunes to watch the video. I hope after listening to it you will feel better (I did) :).</p>]]></content:encoded>
    </item>
    <item>
      <title>Eclipse shows an error on android project but can find the error</title>
      <link>https://docs.microsoft.com/archive/blogs/varunsekhri/eclipse-shows-an-error-on-android-project-but-can-find-the-error</link>
      <pubDate>Fri, 19 Aug 2011 16:50:42 GMT</pubDate>
      <dc:creator><![CDATA[varuns]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/varunsekhri/2011/08/19/eclipse-shows-an-error-on-android-project-but-can-find-the-error/</guid>
      <description><![CDATA[My favorite Android platform on which I can blog so much since its just full of strange behaviors....]]></description>
      <content:encoded><![CDATA[<p>My favorite Android platform on which I can blog so much since its just full of strange behaviors. Latest was this problem where when I build my project then I would see a red mark on the project folder saying the build failed. But then on exanding all folders I would not find any error.</p>
<p>I&nbsp;was looking everywhere what is the problem. Since I am not using ANT&nbsp;and I dont even have a build.log which can tell me exactly what is the problem. In the past following had worked</p>
<p>1) Clean the project</p>
<p>2) Build it again.</p>
<p>No success.</p>
<p>1) Close eclipse and repeat above two steps.</p>
<p>That had worked in the past but this time the error was nasty :).</p>
<p>So I spent some time searching on net on how to find eclipse build logs. And here is the solution.</p>
<p>1) On Eclipse error log can be seen in Window -&gt; Show View -&gt; Problems</p>
<p>2) Now if you are like me who has selected Project -&gt; Build Automatically, then on startup eclipse tries to load all projects in the workspace&nbsp;and will try to build them if they havent been already. The effect is that I have many projects for which external reference have not been resolved. This means they have lots of errors and the Problems log was full with &gt; 3000 errors.</p>
<p>3) I needed to find the error for only my project. Solution for 2 is that clean all projects and unselect Build Automatically option.</p>
<p>4) If Problems log is still full. Right click-&gt; Select all. Then Right click -&gt; Delete. Now Problems log must be empty.</p>
<p>5) Build only your project again to see the problem.</p>
<p>&nbsp;</p>
<p>So as is I got this funny error. <span style="color: #ff0000;">Error generating final archive: Debug certificate expired on 7/30/10 10:42 </span><br /><span style="color: #ff0000;">PM!</span><br />Now what, another search on the web told me that Android needs a certificate to sign the applications before they get installed. Oh well!</p>
<p>So the solution to my problem was. Go to c:\users\&lt;user name&gt;\.android&nbsp;&nbsp;&nbsp; folder. Delete debug.keystore file and now build in eclipse again. It will create the keystore again and now we can get back to work!!</p>]]></content:encoded>
    </item>
    <item>
      <title>Windbg: putting a break point on managed generic functions</title>
      <link>https://docs.microsoft.com/archive/blogs/varunsekhri/windbg-putting-a-break-point-on-managed-generic-functions</link>
      <pubDate>Sat, 21 May 2011 12:02:34 GMT</pubDate>
      <dc:creator><![CDATA[varuns]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/varunsekhri/2011/05/21/windbg-putting-a-break-point-on-managed-generic-functions/</guid>
      <description><![CDATA[Sometimes its not very straight forward to put breakpoints on generic functions or functions in...]]></description>
      <content:encoded><![CDATA[<p>Sometimes its not very straight forward to put breakpoints on generic functions or functions in generic classes. Typing the full class name correctly could be non trivial and frustrating. Here is something which I always follow:</p>
<p>Use method descriptors with bpmd instead. The syntax is !bpmd -md &lt;method descriptor address&gt; . Then the question is how to get the method descriptor address.</p>
<p>Use !dumpdomain &ndash; this will list all the modules in all application domains (most applications have only one appdomain). </p>
<p>Take the module name where your type exists and read the module address</p>
<p>!dumpmodule &ndash;mt &lt;module address&gt;</p>
<p>This will list the types in the module. Now pick up your types address and </p>
<p>!dumpmt &ndash;md &lt;type address&gt;</p>
<p>This will list all the method descriptor addresses of your type and this is what we need to put a break point. </p>
<p>!bpmd &ndash;md &lt;method descriptor address&gt; </p>]]></content:encoded>
    </item>
    <item>
      <title>Android Https Quirks</title>
      <link>https://docs.microsoft.com/archive/blogs/varunsekhri/android-https-quirks</link>
      <pubDate>Sun, 17 Oct 2010 11:54:42 GMT</pubDate>
      <dc:creator><![CDATA[varuns]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/varunsekhri/2010/10/17/android-https-quirks/</guid>
      <description><![CDATA[I wanted to make my own Https Get/Post request on Android platform. In this blog post I will cover...]]></description>
      <content:encoded><![CDATA[<p><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;">I wanted to make my own Https Get/Post request on Android platform. In this blog post I will cover my investigation and the quirks I noticed for eg.</span></span></p>
<p><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;">-&nbsp;if you are working over wifi behind a proxy server or 3G. </span></span></p>
<p><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;">- or what classes to use. </span></span></p>
<p><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;">A standard Http 1.1 requests can be&nbsp;made using Java standard HttpUrlConnection class. There is a separate HttpsUrlConnection class for https connections. But now you will also have to write code if(http) use HttpUrlConnection elseif(https) use HttpsUrlConnection.</span></span></p>
<p><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;">However, Android comes with Apache </span></span><a href="https://blogs.msdn.com/controlpanel/blogs/posteditor.aspx/HttpClient" title="https://hc.apache.org/httpclient-3.x/"><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;">HttpClient </span></span></a><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;">library (which builds on Sockets) and </span></span></p>
<ul type="disc" style="margin-top: 0in; unicode-bidi: embed; direction: ltr; margin-bottom: 0in; margin-left: 0.375in;">
<li style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle;"><span style="font-size: 11pt;"><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;">is much more powerful </span></span></span></li>
<li style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle;"><span style="font-size: 11pt;"><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;">easy to configure different settings,eg, https, http, proxy settings etc. </span></span></span></li>
<li style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle;"><span style="font-size: 11pt;"><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;">Easy to use. </span></span></span></li>
<li style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle;"><span style="font-size: 11pt;"><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;">It has a tutorial to get you going and if in doubt just read the code (its open source)!</span></span></span></li>
</ul>
<p style="margin: 0in 0in 0in 0.375in; font-size: 11pt;"><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;">&nbsp;</span></span></p>
<p style="margin: 0in; font-size: 11pt;"><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;">Android itself uses this library at various places. </span></span></p>
<p style="margin: 0in; font-size: 11pt;"><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;">&nbsp;</span></span></p>
<p style="margin: 0in; font-size: 11pt;"><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;">My experience: </span></span></p>
<ul type="disc" style="margin-top: 0in; unicode-bidi: embed; direction: ltr; margin-bottom: 0in; margin-left: 0.375in;">
<li style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle;"><span style="font-size: 11pt;"><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;">HttpUrlConnection will work over 3G with external sites. However, when you are connected to wifi it will stop working due to proxy settings. I don&rsquo;t know at this point how to set the proxy settings.</span></span></span></li>
<li style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle;"><span style="font-size: 11pt;"><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;">HttpClient will work with internal websites without setting proxy and external websites with setting proxy. Remember to use full fqdn always eg. </span></span></span><a href="https://www.google.com/"><span style="font-size: 11pt;"><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;">https://www.google.com</span></span></span></a><span style="font-size: 11pt;"><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;">. </span></span></span></li>
</ul>
<p style="margin: 0in; font-size: 11pt;"><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;">&nbsp;</span></span></p>
<p style="margin: 0in 0in 0in 1.125in; font-size: 11pt;"><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;">// set proxy</span></span></p>
<p style="margin: 0in 0in 0in 1.125in; font-size: 11pt;"><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;">HttpHost proxy = new HttpHost("myproxy server", 80);</span></span></p>
<p style="margin: 0in 0in 0in 1.125in; font-size: 11pt;"><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;">&nbsp;</span></span></p>
<p style="margin: 0in 0in 0in 1.125in; font-size: 11pt;"><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;">HttpParams params = new BasicHttpParams();</span></span></p>
<p style="margin: 0in 0in 0in 1.125in; font-size: 11pt;"><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;">params.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);</span></span></p>
<p style="margin: 0in 0in 0in 1.125in; font-size: 11pt;"><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;">&nbsp;</span></span></p>
<p style="margin: 0in 0in 0in 1.125in; font-size: 11pt;"><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;">HttpClient httpClient = new DefaultHttpClient(this.manager, params); // this.manager is an instance of HttpConnectionManager</span></span></p>
<p style="margin: 0in 0in 0in 0.375in; font-size: 11pt;"><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;">&nbsp;</span></span></p>
<ul type="disc" style="margin-top: 0in; unicode-bidi: embed; direction: ltr; margin-bottom: 0in; margin-left: 0.375in;">
<li style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle;"><span style="font-size: 11pt;"><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;">Https connections over HttpClient is&nbsp;also very straight forward. A bit reading on Java SSL and SocketFactory is required. And then read the tutorial on HttpClient website. It takes around&nbsp;1-2 hours to read the material and then its all very easy.</span></span></span></li>
<li style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle;"><span style="font-size: 11pt;"><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;">If you are sending HttpRequest over Https and need&nbsp;to handle with self signed certificates. You will have to create EasySSLSocketFactory and EasyX509TrustManager. Again the tutorial has all the details.</span></span></span></li>
</ul>
<p style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle;"><span style="font-size: 11pt;"><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;"></span></span></span></p>
<p style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle;"><span style="font-size: x-small;"></span><span style="font-family: Calibri; font-size: 11pt;"></span></p>
<p style="margin: 0in; font-family: Calibri; font-size: 11pt;"><span style="font-weight: bold;"><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;">WebView quirks</span></span></span></p>
<p style="margin: 0in; font-size: 11pt;"><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;">&nbsp;</span></span></p>
<p style="margin: 0in; font-size: 11pt;"><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;">WebView behaves like the browser. All of the below is true for wifi.</span></span></p>
<ul type="disc" style="margin-top: 0in; unicode-bidi: embed; direction: ltr; margin-bottom: 0in; margin-left: 0.375in;">
<li style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle;"><span style="font-size: 11pt;"><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;">Proxy not set. Both will deny access to external sites. Allows access to the internal sites.</span></span></span></li>
<li style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle;"><span style="font-size: 11pt;"><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;">Proxy set. Both will deny access to internal sites and deny access to external sites.</span></span></span></li>
</ul>
<p style="margin: 0in; font-size: 11pt;"><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;">&nbsp;</span></span></p>
<p style="margin: 0in; font-size: 11pt;"><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;">Https Connections. </span></span></p>
<ul type="disc" style="margin-top: 0in; unicode-bidi: embed; direction: ltr; margin-bottom: 0in; margin-left: 0.375in;">
<li style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle;"><span style="font-size: 11pt;"><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;">When working with browser you will get a warning for the websites which uses self signed certificates. </span></span></span></li>
<li style="margin-top: 0px; margin-bottom: 0px; vertical-align: middle;"><span style="font-size: 11pt;"><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;">When working with Webview you will need to override a function in WebViewClient class </span></span></span></li>
</ul>
<p style="margin: 0in 0in 0in 0.375in; font-size: 11pt;"><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;">public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error)</span></span></p>
<p style="margin: 0in 0in 0in 0.375in; font-family: Calibri; font-size: 11pt;"><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;">Unfortunately, the function is not present on Android 2.1. Fortunately, there is an easy workaround which can be </span></span><a href="https://r3gis.fr/blog/index.php?post/2009/11/17/Android-WebView-and-ssl-self-signed-certificates"><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;">followed</span></span></a><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;">.</span></span></p>
<p><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;">&nbsp;</span></span></p>]]></content:encoded>
    </item>
    <item>
      <title>Android Webview behind proxy</title>
      <link>https://docs.microsoft.com/archive/blogs/varunsekhri/android-webview-behind-proxy</link>
      <pubDate>Sun, 19 Sep 2010 21:48:46 GMT</pubDate>
      <dc:creator><![CDATA[varuns]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/varunsekhri/2010/09/19/android-webview-behind-proxy/</guid>
      <description><![CDATA[Lately I have been working on Android platform.&nbsp;If you are behind a proxy in your company and...]]></description>
      <content:encoded><![CDATA[<p>Lately I have been working on Android platform.&nbsp;If you are behind a proxy in your company and working with the simulator here are the steps to get the browser working</p>
<p>Settings -&gt; Wireless Networks -&gt;mobile networks-&gt; access point names-&gt;telkila. Now enter the proxy server address and port (which will be 80).</p>
<p>However, if you are working with WebView control in your app then above will not work unless your code has following line in onCreate()</p>
<p><span style="font-size: x-small;">
<p>WebView.<i>enablePlatformNotifications</i>();</p>
<p>You might want to restart the emulator after this to test your app again. </p>
</span></p>]]></content:encoded>
    </item>
    <item>
      <title>How long does it take to install Windows Phone 7 SDK</title>
      <link>https://docs.microsoft.com/archive/blogs/varunsekhri/how-long-does-it-take-to-install-windows-phone-7-sdk</link>
      <pubDate>Sun, 18 Jul 2010 15:55:48 GMT</pubDate>
      <dc:creator><![CDATA[varuns]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/varunsekhri/2010/07/18/how-long-does-it-take-to-install-windows-phone-7-sdk/</guid>
      <description><![CDATA[I started installation of Windows Phone 7 SDK from&nbsp;this link&nbsp;over my machine
- Windows...]]></description>
      <content:encoded><![CDATA[<p>I started installation of Windows Phone 7 SDK from&nbsp;<a href="https://www.microsoft.com/downloads/details.aspx?FamilyID=c8496c2a-54d9-4b11-9491-a1bfaf32f2e3&amp;displaylang=en">this link&nbsp;</a>over my machine</p>
<p>- Windows 7</p>
<p>- x64 dual proc</p>
<p>- 2GB RAM.</p>
<p>- Visual Studio 2010 professional</p>
<p>- Office 2010.</p>
<p>The download of 322 MB completed fairly quickly. The installation took more than an hour. Phew!!! Even my OS (windows 7)&nbsp;installation was&nbsp;quicker than that. </p>
<p>I hope this experience gets improved. Anyways now I shall write my first app :).</p>]]></content:encoded>
    </item>
    <item>
      <title>Certificate management for Exchange Unified Messaging 2010</title>
      <link>https://docs.microsoft.com/archive/blogs/varunsekhri/certificate-management-for-exchange-unified-messaging-2010</link>
      <pubDate>Sun, 26 Jul 2009 19:05:00 GMT</pubDate>
      <dc:creator><![CDATA[varuns]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/varunsekhri/2009/07/26/certificate-management-for-exchange-unified-messaging-2010/</guid>
      <description><![CDATA[Microsoft Exchange Unified Messaging 2010 will be released with a lot of goodies. One of them is to...]]></description>
      <content:encoded><![CDATA[<P>Microsoft Exchange Unified Messaging 2010 will be released with a lot of goodies. One of them is to give more control to the admins so that they can hand pick the certificate with which they want Microsoft Exchange Unified Messaging service to run.</P>
<P>In UM Exchnage 2007 the service would automatically choose&nbsp;what "it thinks" is the best certificate in the machine store. However, the customer feedback told us to change this design and let admins specify what certificate to choose and tell UM for making the connections using TLS. And with this new design you dont have to learn any new cmdlets: <STRONG>*-exchangecertificate cmdltes can be used to create and assign a certificate to UM service.</STRONG></P>
<P>Admins&nbsp;of Exchange&nbsp;2007 who have used UM to make connection only over TCP will not have to make any changes. Out of the box UM continues to make connections over&nbsp;TCP <EM>only.</EM>&nbsp;</P>
<P>Admins who want to accept or make secured calls using TLS will have to do following three steps. I have given some examples below.</P>
<P>- Change the mode of UM service from TCP to&nbsp;Dual or TLS. Dual mode means that the UM service will listen for calls on both TCP and TLS. TLS means that UM will listen only over TLS. </P>
<P>- Get a new certificate. </P>
<P>- Assign the certificate to UM and restart the service.</P>
<P>Finally, take steps so that the IP Gateway will trust and accept this certificate. </P>
<P>Here are some examples to do what I have mentioned above using powershell cmdlets. Same can be acheived using EMC as well. I will not be going through the EMC in this blog post.</P>
<P>1. Change the mode of the server to Dual or&nbsp;TLS&nbsp;using set-umserver cmdlet. As you can see it nicely gives warnings as to what are next steps.</P>
<P><STRONG>&nbsp;[PS] D:\Windows\system32&gt;set-umserver -UMStartupMode dual -Identity EXCH-I-349<BR></STRONG><FONT color=#e56717>WARNING: Changes to UMStartupMode will only take effect after the Microsoft Exchange Unified Messaging service is<BR>restarted on server EXCH-I-349.<BR>WARNING: To complete TLS setup, do all of the following: (1) Create a new certificate using the New-ExchangeCertificate<BR>&nbsp;cmdlet (2) Associate this certificate with the Unified Messaging server using the Enable-ExchangeCertificate cmdlet<BR>(3) For self-signed certificates, copy this certificate to the UM IP gateway and&nbsp; correctly import it. For CA-signed<BR>certificates, correctly import the CA certificate to the UM IP gateway.</FONT></P>
<P>2. To get a new certificate, you can use new-exchangecertificate cmdlet. This cmdlet can be used to create a new self signed certificate or a new certificate request. Details of the cmdlet can be seen at <A href="https://technet.microsoft.com/en-us/library/aa998327.aspx" mce_href="https://technet.microsoft.com/en-us/library/aa998327.aspx">msdn</A>.</P>
<P><STRONG>[PS] D:\Windows\system32&gt;New-ExchangeCertificate -Services none -Server EXCH-I-349</STRONG></P>
<P>Thumbprint&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Services&nbsp;&nbsp; Subject<BR>----------&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --------&nbsp;&nbsp; -------<BR>80FAC0BC54F7282D14D326C34F80B02C3AA668CF&nbsp; IP....&nbsp;&nbsp;&nbsp;&nbsp; CN=EXCH-I-349</P>
<P>In the above example I have created a new self signed certificate which is present in the UM server's machine store and can be used by any MS Exchange service.</P>
<P>3) Assign the above generated self signed certificate to UM.</P>
<P><STRONG>[PS] D:\Windows\system32&gt;Enable-ExchangeCertificate -Services UM -Thumbprint 80FAC0BC54F7282D14D326C34F80B02C3AA668CF -s<BR>erver EXCH-I-349</STRONG></P>
<P>Confirm<BR>Enable certificate with thumbprint 80FAC0BC54F7282D14D326C34F80B02C3AA668CF for Unified Messaging?<BR>[Y] Yes&nbsp; [A] Yes to All&nbsp; [N] No&nbsp; [L] No to All&nbsp; [?] Help (default is "Y"): yes<BR><FONT color=#e56717>WARNING: To complete configuration (1) Restart Microsoft Exchange Unified Messaging Service on EXCH-I-349 and (2) For<BR>self-signed certificates, install this certificate on the UM IP Gateway. For CA-signed certificates, import the CA<BR>certificate on the UM IP Gateway.</FONT></P>
<P>Again&nbsp;notice the warning it gives.</P>
<P>4)&nbsp;Restart UM service so that it starts listening on TLS.</P>
<P>5) As specified by the warnings in the cmdlets ensure that the IP gateway trusts the certifcate used by the UM service. The warnings themselves are self explanatory that I wont be going through them again.</P>
<P>6) Check the certificate used by the services</P>
<P><STRONG>[PS] D:\Windows\system32&gt;Get-ExchangeCertificate</STRONG></P>
<P>Thumbprint&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Services&nbsp;&nbsp; Subject<BR>----------&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --------&nbsp;&nbsp; -------<BR>80FAC0BC54F7282D14D326C34F80B02C3AA668CF&nbsp; <STRONG>IPU...</STRONG>&nbsp;&nbsp;&nbsp;&nbsp; CN=EXCH-I-349<BR>3F4FF713FE8A604BCD84B20075B354DFCE36742B&nbsp; IP.WS.&nbsp;&nbsp;&nbsp;&nbsp; CN=EXCH-I-349</P>
<P mce_keep="true">&nbsp;</P>
<P mce_keep="true">If your were using a self signed certificate then you could combine steps 2 and 3 together.</P>
<P mce_keep="true"><STRONG>[PS] D:\Windows\system32&gt;New-ExchangeCertificate -Services UM -Server EXCH-I-349</STRONG></P>
<P mce_keep="true">Confirm<BR>Enable certificate with thumbprint 7B14E7BDF61F6461FBF32D4570B7DBE65E136B67 for Unified Messaging?<BR>[Y] Yes&nbsp; [A] Yes to All&nbsp; [N] No&nbsp; [L] No to All&nbsp; [?] Help (default is "Y"): yes</P>
<P mce_keep="true">Thumbprint&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Services&nbsp;&nbsp; Subject<BR>----------&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --------&nbsp;&nbsp; -------<BR>7B14E7BDF61F6461FBF32D4570B7DBE65E136B67&nbsp; IPU...&nbsp;&nbsp;&nbsp;&nbsp; CN=EXCH-I-349</P>
<P mce_keep="true">&nbsp;</P>
<P mce_keep="true">&nbsp;</P>]]></content:encoded>
    </item>
    <item>
      <title>Debugging a managed 64 bit service</title>
      <link>https://docs.microsoft.com/archive/blogs/varunsekhri/debugging-a-managed-64-bit-service</link>
      <pubDate>Tue, 22 Apr 2008 02:00:00 GMT</pubDate>
      <dc:creator><![CDATA[varuns]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/varunsekhri/2008/04/22/debugging-a-managed-64-bit-service/</guid>
      <description><![CDATA[I was trying to put a breakpoint in the Main function of a managed process which was being launched...]]></description>
      <content:encoded><![CDATA[<p>I was trying to put a breakpoint in the Main function of a managed process which was being launched by a managed service. I knew about the <a href="https://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsdebug/html/vxtskLaunchingDebuggerAutomatically.asp" target="_blank" mce_href="https://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsdebug/html/vxtskLaunchingDebuggerAutomatically.asp">IFEO </a>(Image file execution option) and I was trying it with vsjitdebugger.exe but it just would not attach. A little web search led me to great blog entries by <a href="https://blogs.msdn.com/jmstall/archive/2006/02/16/ifeo_managed_debugging.aspx" target="_blank" mce_href="https://blogs.msdn.com/jmstall/archive/2006/02/16/ifeo_managed_debugging.aspx">Mike</a>. The problem was that both the service and the process were not only managed but also 64 bit. Currently, it seems vsjitdebugger.exe does not support this scenario. Anyhow, Mike also has another <a href="https://blogs.msdn.com/jmstall/archive/2005/01/28/362169.aspx" target="_blank" mce_href="https://blogs.msdn.com/jmstall/archive/2005/01/28/362169.aspx">blog entry</a> where he explains a bit on how managed and native debuggers operate.</p><p>But I was still stuck on how to debug the service or the foo.exe launched by the service. The only clean way is to modify our code in the Main function (or OnStart if it is a service) and use <a href="https://msdn2.microsoft.com/en-us/library/system.diagnostics.debugger.launch.aspx" target="_blank" mce_href="https://msdn2.microsoft.com/en-us/library/system.diagnostics.debugger.launch.aspx">Debugger.Launch</a>() (so annoying). </p><p>public static void Main()</p><p>{</p><p>&nbsp;&nbsp;&nbsp; //you can use #define DEBUG also so that this become debug only code&nbsp;</p><p>&nbsp;&nbsp;&nbsp; try </p><p>&nbsp;&nbsp;&nbsp; {</p><p>&nbsp;&nbsp;&nbsp; &nbsp; if (!Debugger.IsAttached)</p><p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;</p><p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Debugger.Launch();</p><p>&nbsp;&nbsp;  &nbsp;&nbsp;  &nbsp;&nbsp;  &nbsp;&nbsp;&nbsp; Debugger.Break();<br>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p>&nbsp;&nbsp;&nbsp; }</p><p>&nbsp;&nbsp;&nbsp; catch (Exception ex)</p><p>&nbsp;&nbsp;&nbsp; {</p><p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //log and see which exception was thrown.<br>&nbsp;</p><p>&nbsp;&nbsp;&nbsp; }&nbsp;</p><p>&nbsp;&nbsp;&nbsp; // continue with your main function&nbsp;</p><p>}&nbsp;</p><p>But then I was interested in how things work here.</p><p>Q . How does Debugger.Launch() know which debugger to start and where is it listed? <br> </p><p>&nbsp;<a href="https://blogs.msdn.com/jmstall/archive/2006/07/24/caveats_about_jit_debugging.aspx" mce_href="https://blogs.msdn.com/jmstall/archive/2006/07/24/caveats_about_jit_debugging.aspx">Ans. </a><br></p><p><br></p>]]></content:encoded>
    </item>
    <item>
      <title>Some good books .....</title>
      <link>https://docs.microsoft.com/archive/blogs/varunsekhri/some-good-books</link>
      <pubDate>Wed, 02 Jan 2008 14:04:00 GMT</pubDate>
      <dc:creator><![CDATA[varuns]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/varunsekhri/2008/01/02/some-good-books/</guid>
      <description><![CDATA[If you dont know about the aha! factor then&nbsp;read the book - &nbsp;Programming Pearls by Jon...]]></description>
      <content:encoded><![CDATA[<P>If you dont know about the <EM>aha!</EM> factor then&nbsp;read the book - &nbsp;Programming Pearls by Jon Bentley. The problems and the solutions will definitely make you say <EM>aha! </EM>:).</P>
<P>The next one on my reading list is The Medical Detectives by Berton Roueche</P>
<P>PS: I&nbsp;will update this blog entry whenever I happen to find such great books.</P>]]></content:encoded>
    </item>
    <item>
      <title>How do we talk with COM the language of events and delegates</title>
      <link>https://docs.microsoft.com/archive/blogs/varunsekhri/how-do-we-talk-with-com-the-language-of-events-and-delegates</link>
      <pubDate>Tue, 18 Sep 2007 20:38:00 GMT</pubDate>
      <dc:creator><![CDATA[varuns]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/varunsekhri/2007/09/18/how-do-we-talk-with-com-the-language-of-events-and-delegates/</guid>
      <description><![CDATA[I wrote this blog entry from a real world&nbsp;customer issue and noticed that how...]]></description>
      <content:encoded><![CDATA[<div>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="3">I wrote this blog entry from a real world&nbsp;customer issue and noticed that how little&nbsp;documentation exists&nbsp;on this topic. </font></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="3">I assume that you already know what is a source interface in COM and&nbsp;what are&nbsp;IConnectionPoint and IConnectionPointContainer interfaces.&nbsp;Please pick up any COM book to learn that (I would reccommend Essential COM by Don Box). Also, a familiarity with the events and delegates would help.</font></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="3">The example code in this article are picked up from a real world scenario given by a customer.</font></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="3"></font>&nbsp;</p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="3">Lets assume that we have a COM server which has a source interface as defined in the following IDL.</font></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: 'Courier New';">Note: The best way to learn from this&nbsp;article would be to </span></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: 'Courier New';">1) create a typelibrary from the IDL given above</span></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: 'Courier New';">2) create the interop dll using tlbimp.exe </span></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: 'Courier New';">3) Use ildasm to read what is written inside the interop dll.</span></p>
<span style="font-size: 10pt; color: blue; font-family: 'Courier New';"><font color="#0000ff" size="2">
</font>
<p><font color="#0000ff" size="2">//Start of the idl</font></p>

<p><font color="#0000ff" size="2">import</font><font color="#000000" size="2"> </font><font color="#800000" size="2">"oaidl.idl"</font><font size="2"><font color="#000000">;</font></font></p>
<font color="#0000ff" size="2">
</font>
<p><font color="#0000ff" size="2">import</font><font color="#000000" size="2"> </font><font color="#800000" size="2">"ocidl.idl"</font><font size="2"><font color="#000000">;</font></font></p>

<p><font size="2">[</font></p>

<p><font color="#0000ff" size="2">object</font><font size="2">,</font></p>

<p><font color="#0000ff" size="2">uuid</font><font size="2">(E3AA8979-3038-4CCD-BA37-13F29F1E61F1),</font></p>

<p><font color="#0000ff" size="2">dual</font><font size="2">,</font></p>

<p><font color="#0000ff" size="2">nonextensible</font><font size="2">,</font></p>

<p><font color="#0000ff" size="2">helpstring</font><font size="2">(</font><font color="#800000" size="2">"ILegacyComObject Interface"</font><font size="2">),</font></p>

<p><font color="#0000ff" size="2">pointer_default</font><font size="2">(</font><font color="#0000ff" size="2">unique</font><font size="2">)</font></p>

<p><font size="2">]</font></p>
<font color="#0000ff" size="2">
</font>
<p><font color="#0000ff" size="2">interface</font><font size="2"><font color="#000000"> ILegacyComObject : IDispatch{</font></font></p>

<p><font size="2">[</font><font color="#0000ff" size="2">id</font><font size="2">(1), </font><font color="#0000ff" size="2">helpstring</font><font size="2">(</font><font color="#800000" size="2">"method DoSomething"</font><font size="2">)] HRESULT DoSomething(</font><font color="#0000ff" size="2">void</font><font size="2">);</font></p>

<p><font size="2">};</font></p>

<p><font size="2">[</font></p>

<p><font color="#0000ff" size="2">uuid</font><font size="2">(CD839D63-B5CB-4236-825F-9EF2C943261B),</font></p>

<p><font color="#0000ff" size="2">version</font><font size="2">(1.0),</font></p>

<p><font color="#0000ff" size="2">helpstring</font><font size="2">(</font><font color="#800000" size="2">"AtlComClient 1.0 Type Library"</font><font size="2">)</font></p>

<p><font size="2">]</font></p>
<font color="#0000ff" size="2">
</font>
<p><font color="#0000ff" size="2">library</font><font size="2"><font color="#000000"> AtlComClientLib</font></font></p>

<p><font size="2">{</font></p>

<p><font color="#0000ff" size="2">importlib</font><font size="2">(</font><font color="#800000" size="2">"stdole2.tlb"</font><font size="2">);</font></p>

<p><font size="2">[</font></p>

<p><font color="#0000ff" size="2">uuid</font><font size="2">(C23B1EFE-1A27-4200-B14C-5F2019E024C5),</font></p>

<p><font color="#0000ff" size="2">nonextensible</font><font size="2">,</font></p>

<p><font color="#0000ff" size="2">helpstring</font><font size="2">(</font><font color="#800000" size="2">"_ILegacyComObjectEvents Interface"</font><font size="2">)</font></p>

<p><font size="2">]</font></p>

<p><font color="#0000ff" size="2">dispinterface</font><font size="2"> _ILegacyComObjectEvents</font></p>

<p><font size="2">{</font></p>

<p><font color="#0000ff" size="2">properties</font><font size="2">:</font></p>

<p><font color="#0000ff" size="2">methods</font><font size="2">:</font></p>

<p><font size="2">[</font><font color="#0000ff" size="2">id</font><font size="2">(1) ] VARIANT_BOOL CanDoSomething();</font></p>

<p><font size="2">[</font><font color="#0000ff" size="2">id</font><font size="2">(2) ] </font><font color="#0000ff" size="2">void</font><font size="2"> DoneSomething();</font></p>

<p><font size="2">};</font></p>

<p><font size="2">[</font></p>

<p><font color="#0000ff" size="2">uuid</font><font size="2">(A2272EDE-8103-43A7-A819-286EAE2C2A0A),</font></p>

<p><font color="#0000ff" size="2">helpstring</font><font size="2">(</font><font color="#800000" size="2">"LegacyComObject Class"</font><font size="2">)</font></p>

<p><font size="2">]</font></p>

<p><font color="#0000ff" size="2">coclass</font><font size="2"> LegacyComObject</font></p>

<p><font size="2">{</font></p>

<p><font size="2">[</font><font color="#0000ff" size="2">default</font><font size="2">] </font><font color="#0000ff" size="2">interface</font><font size="2"> ILegacyComObject;</font></p>

<p><font size="2">[</font><font color="#0000ff" size="2">default</font><font size="2">, </font><font color="#0000ff" size="2">source</font><font size="2">] </font><font color="#0000ff" size="2">dispinterface</font><font size="2"> _ILegacyComObjectEvents;</font></p>

<p><font size="2">};</font></p>

<p><font size="2">};</font></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font size="2">//End of the idl</font></p>
</span>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: 'Courier New';"></span>&nbsp;</p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: 'Courier New';"></span>&nbsp;</p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: 'Courier New';"></span>&nbsp;</p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: 'Courier New';">In common terms we also say that the com server supports two "<i>events</i>" CanDoSomething and DoneSomething.</span></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="3">NOTE: ILegacyComObject is just some implemented interface by the com server. </font></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="3"></font><font face="Times New Roman" size="3"></font>&nbsp;</p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="3">When we&nbsp;create an inteop dll using tlbimp.exe it will contain the following classes and interfaces. </font></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="3"></font>&nbsp;</p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="3">1) We need two delegates for the two events defined. Our naming convention is &lt;interfacename&gt;_&lt;event name&gt;EventHandler. Also note that since delegates are types so we will have two classes defined in the interop dll by the name:</font></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="3">_ILegacyComObjectEvents_CanDoSomethingEventHandler</font></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="3">_ILegacyComObjectEvents_DoneSomethingEventHandler</font></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="3"></font>&nbsp;</p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="3">2) We have an interface defined as _ILegacyComObjectEvents with the correct ComVisible and GUID attributes.</font></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="3"></font>&nbsp;</p>

<p class="MsoNormal" style="margin: 0in 0in 0pt; vertical-align: top; line-height: 140%;"><font face="Times New Roman" size="3">3) Tlbimp.exe also creates a second event interface, designated by the "_Event" suffix added to the name of the original interface. This second event interface has DoneSomething and <tt><span style="line-height: 140%; font-family: 'Times New Roman';">CanDoSomething</span></tt> events as members. It also has <font size="4"><tt><span style="line-height: 140%; font-family: 'Times New Roman';">add</span></tt> <font size="3">and <tt><span style="line-height: 140%; font-family: 'Times New Roman';">remove</span></tt> methods for the event delegates. In this example, the interface is called </font><tt><span style="line-height: 140%; font-family: 'Times New Roman';">_ILegacyComObjectEvents_Event</span></tt>. </font></font></p>

<p class="MsoNormal">&nbsp;<font size="3"><font face="Times New Roman">4) The coclass generated would implement ILegacyComObject and </font></font><tt><span style="font-size: 11pt; font-family: 'Times New Roman';">_ILegacyComObjectEvents_Event
(Note) and be named as LegacyComObjectClass. For points 3 and 4 also msdn has
some good&nbsp;article <a href="https://msdn2.microsoft.com/en-us/library/k639e386.aspx" mce_href="https://msdn2.microsoft.com/en-us/library/k639e386.aspx">https://msdn2.microsoft.com/en-us/library/k639e386.aspx</a></span></tt><span style="font-size: 13pt;"><o:p></o:p></span></p>


<p class="MsoNormal" style="margin: 0in 0in 0pt; vertical-align: top; line-height: 140%;"><tt><span style="line-height: 140%; font-family: 'Times New Roman';"></span></tt> <tt><span style="line-height: 140%; font-family: 'Times New Roman';"><font size="3">5) We generate a class &lt;source interface name&gt;_SinkHelper which implements the source interface methods (or in other words it implements _ILegacyComObject interface). Thus we would pass an instance of this class everytime IConnectionPoint::Advise is called. This class also stores the cookie returned from Advise.</font></span></tt></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt; vertical-align: top; line-height: 140%;"><tt><span style="line-height: 140%; font-family: 'Times New Roman';"><font size="3"></font></span></tt>&nbsp;</p>

<p class="MsoNormal" style="margin: 0in 0in 0pt; vertical-align: top; line-height: 140%;"><tt><span style="line-height: 140%; font-family: 'Times New Roman';"><font size="3">Here is the pseudo code of the class</font></span></tt></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font size="2"><tt><span style="font-family: 'Times New Roman';"></span></tt></font>&nbsp;</p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font size="2"><tt><span style="font-family: 'Times New Roman';">class _ILegacyComObjectEvents_SinkHelper : </span></tt><font face="Times New Roman">_ILegacyComObjectEvents<tt><span style="font-family: 'Times New Roman';"></span></tt></font></font></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt; vertical-align: top; line-height: 140%;"><tt><span style="font-size: 10pt; line-height: 140%; font-family: 'Times New Roman';">{</span></tt></p>

<p class="sourcecode" style="margin: 0in 0in 0pt; text-indent: 4.5pt;"><font size="2"><tt><span style="font-family: 'Times New Roman';"><span>&nbsp; </span>//store the cookie returned </span></tt><span class="sourcecodeChar"><span style="font-family: 'Times New Roman';">from the IConnectionPoint::Advise call</span></span><tt><span style="font-family: 'Times New Roman';"></span></tt></font></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt; vertical-align: top; line-height: 140%;"><tt><span style="font-size: 10pt; line-height: 140%; font-family: 'Times New Roman';"><span>&nbsp; </span>public Int m_dwCookie; </span></tt></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt; text-indent: 4.5pt;"><tt><span style="font-size: 10pt; font-family: 'Times New Roman';">// store the delegates from the user </span></tt></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt; text-indent: 4.5pt;"><tt><span style="font-size: 10pt; font-family: 'Times New Roman';">public</span></tt><span style="font-size: 10pt;"><font face="Times New Roman"> _ILegacyComObjectEvents_CanDoSomethingEventHandler m_CanDoSomethingDelegate;</font></span></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt; text-indent: 4.5pt;"><span style="font-size: 10pt;"><font face="Times New Roman"></font></span>&nbsp;</p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><tt><span style="font-size: 10pt; font-family: 'Times New Roman';"><span>&nbsp; </span>public</span></tt><span style="font-size: 10pt;"><font face="Times New Roman"> _ILegacyComObjectEvents_DoneSomethingEventHandler m_DoneSomethingDelegate;</font></span></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt;"><font face="Times New Roman"></font></span>&nbsp;</p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt;"><font face="Times New Roman"><span>&nbsp;</span><tt><span style="font-family: 'Times New Roman';">ILegacyComObject_SinkHelper () </span></tt></font></span></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><tt><span style="font-size: 10pt; font-family: 'Times New Roman';">{</span></tt></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><tt><span style="font-size: 10pt; font-family: 'Times New Roman';"><span>&nbsp;</span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>m_dwCookie = NULL;</span></tt></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt; text-indent: 0.5in;"><span style="font-size: 10pt;"><font face="Times New Roman">m_CanDoSomethingDelegate= NULL;</font></span></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt; text-indent: 0.5in;"><span style="font-size: 10pt;"><font face="Times New Roman">m_DoneSomethingDelegate = NULL;<tt><b><span style="font-family: 'Times New Roman';"></span></b></tt></font></span></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><tt><span style="font-size: 10pt; font-family: 'Times New Roman';">}</span></tt></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><tt><span style="font-size: 10pt; font-family: 'Times New Roman';"></span></tt>&nbsp;</p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt;"><font face="Times New Roman">bool CanDoSomething()</font></span></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt;"><font face="Times New Roman">{</font></span></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt;"><font face="Times New Roman"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>if (m_CanDoSomethingDelegate ! = NULL)</font></span></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt; text-indent: 0.5in;"><span style="font-size: 10pt;"><font face="Times New Roman">return m_CanDoSomethingDelegate.Invoke(); //Invoke the delegate</font></span></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt;"><font face="Times New Roman"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>return 0;<span>&nbsp;&nbsp; </span>// notice the default value </font></span></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt;"><font face="Times New Roman">// See the Notes below for the return type</font></span></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt;"><font face="Times New Roman">}</font></span></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt;"><font face="Times New Roman">void DoneSomething()</font></span></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt;"><font face="Times New Roman">{</font></span></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt;"><font face="Times New Roman"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>if (m_DoSomethingDelegate ! = NULL)</font></span></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt;"><font face="Times New Roman"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>return m_DoSomethingDelegate.Invoke(); //Invoke the delegate</font></span></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt;"><font face="Times New Roman"><span>&nbsp;&nbsp; </span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>return;</font></span></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt;"><font face="Times New Roman">}</font></span></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt; vertical-align: top; line-height: 140%;"><tt><span style="font-size: 10pt; line-height: 140%; font-family: 'Times New Roman';">}</span></tt></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="3"></font>&nbsp;</p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="3">6) We generate an EventProvider with name &lt;source interface name&gt;_EventProvider</font></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="3">This is the main class which provides the inter-operation between the COM server and the client. Note that it also implements the IDisposable interface.</font></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="3"></font>&nbsp;</p>

<p class="sourcecode" style="margin: 0in 0in 0pt;">
</p>
<p class="MsoNormal"><span style="font-size: 11pt;">Here is the pseudoCode.</span></p>
<p class="MsoNormal"><span style="font-size: 11pt;"></span>class _ILegacyComObjectEvents_EventProvider: IDisposable, _ILegacyComObjectEvents_Event</p>
<font face="Times New Roman" size="2"></font>
<p class="sourcecode" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="2">{</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="2">// store the IConnectionPoint object from the COM server here</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="2">IConnectionPoint m_ConnectionPoint;</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="2"></font>&nbsp;</p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="2">// runtime will provide the implementation of this </font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="2">IConnectionPointContainer m_ConnectionPointContainer;</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="2"></font>&nbsp;</p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="2">//arraylist of object of type SinkHelpers</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="2">ArrayList m_aEventSinkHelpers; </font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="2"></font>&nbsp;</p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="2">public _ILegacyComObject_EventProvider(Object A1)</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="2">{</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font size="2"><font face="Times New Roman"><span>&nbsp; </span>m_ConnectionPointContainer = (IConnectionPointContainer)A1;</font></font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="2">}</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="2"></font>&nbsp;</p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="2">void Dispose()</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="2">{</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt; text-indent: 4.5pt;"><font face="Times New Roman" size="2">_ILegacyComObjectEvents_EventProvider::Finalize();</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt; text-indent: 4.5pt;"><font face="Times New Roman" size="2">GC.SuppressFinalize();</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="2">}</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="2">void Finalize()</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="2">{</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font size="2"><font face="Times New Roman"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>// save yourself from the threading issues</font></font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt; text-indent: 0.5in;"><font face="Times New Roman" size="2">System.Threading.Monitor::Enter(this);</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font size="2"><font face="Times New Roman"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>try </font></font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt; text-indent: 0.5in;"><font face="Times New Roman" size="2">{</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt; text-indent: 0.5in;"><font face="Times New Roman" size="2">for (each x in m_aEventSinkHelpers)</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt; text-indent: 0.5in;"><font face="Times New Roman" size="2">{</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt; text-indent: 0.5in;"><font size="2"><font face="Times New Roman"><span>&nbsp; </span>// call unadivse on each connection made</font></font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt; text-indent: 0.5in;"><font size="2"><font face="Times New Roman"><span>&nbsp;</span><span>&nbsp;</span>m_ConnectionPoint.UnAdvise(((<tt><span style="font-family: 'Times New Roman';">_ILegacyComObject</span></tt></font></font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt; text-indent: 0.5in;"><font size="2"><font face="Times New Roman"><tt><span style="font-family: 'Times New Roman';">Events_SinkHelper</span></tt>)x).m_dwCookie);</font></font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt; text-indent: 0.5in;"><font face="Times New Roman" size="2">}</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt; text-indent: 0.5in;"><font face="Times New Roman" size="2">System.Runtime.InteropServices.Marshal::ReleaseComObject(m_ConnectionPoint);</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font size="2"><font face="Times New Roman"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}//end try</font></font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font size="2"><font face="Times New Roman"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>catch (Exception)</font></font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font size="2"><font face="Times New Roman"><span>&nbsp;&nbsp;&nbsp;&nbsp; </span>{</font></font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font size="2"><font face="Times New Roman"><span>&nbsp; </span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></font></font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font size="2"><font face="Times New Roman"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}//end catch</font></font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font size="2"><font face="Times New Roman"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>finally</font></font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font size="2"><font face="Times New Roman"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</font></font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt; text-indent: 0.5in;"><font face="Times New Roman" size="2">System.Threading.Monitor::Exit(this);</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font size="2"><font face="Times New Roman"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}//end finally</font></font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="2">}//end of Finalize</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="2"></font>&nbsp;</p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="2">// This function gets the IConnectionPoint implementation from the server for the given </font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="2">// interface. Also intializes the arraylist of EventSinkHelpers.</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="2">void Init ()</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="2">{</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt 0.5in;"><font face="Times New Roman" size="2">m_ConnectionPointContainer.FindConnectionPoint(guid of _ILegacyComObject, </font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt 0.5in;"><font size="2"><font face="Times New Roman"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&amp;m_ConnectionPoint);</font></font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font size="2"><font face="Times New Roman"><span>&nbsp;</span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>Initialize the arraylist m_aEventSinkHelpers;</font></font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="2">}//end of Init</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="2"></font>&nbsp;</p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="2">public void add_CanDoSomething(_ILegacyComObjectEvents_CanDoSomethingEventHandler A_1)</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="2">{</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt; text-indent: 0.5in;"><font face="Times New Roman" size="2">//declare some temporary variables.</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt; text-indent: 0.5in;"><font face="Times New Roman" size="2">_ILegacyComObjectEvents_SinkHelper V_0;</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt; text-indent: 0.5in;"><font face="Times New Roman" size="2">// Save yourserlf from the threading issues.</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt; text-indent: 0.5in;"><font size="2"><font face="Times New Roman"><span>&nbsp;</span>System.Threading.Monitor::Enter(this);</font></font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt; text-indent: 0.5in;"><font face="Times New Roman" size="2">try </font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt; text-indent: 0.5in;"><font face="Times New Roman" size="2">{</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt; text-indent: 0.5in;"><font size="2"><font face="Times New Roman"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>// first check whether we have IConnectionPoint with us</font></font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt 0.5in; text-indent: 0.5in;"><font size="2"><font face="Times New Roman"><span>&nbsp;</span>if (m_ConnectionPoint==NULL)</font></font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt; text-indent: 4.5pt;"><font size="2"><font face="Times New Roman"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>Init();</font></font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt 0.5in; text-indent: 0.5in;"><font face="Times New Roman" size="2">V_0 = new _ILegacyComObjectEvents_SinkHelper();</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt 0.5in; text-indent: 0.5in;"><font face="Times New Roman" size="2">//call the advise method</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt 0.5in; text-indent: 0.5in;"><font face="Times New Roman" size="2">m_ConnectionPoint.Advise(V_0, &amp;V_1);</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt 0.5in; text-indent: 0.5in;"><font face="Times New Roman" size="2">// store the delegate and the cookie</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt 0.5in; text-indent: 0.5in;"><font face="Times New Roman" size="2">V_0.m_dwCookie = V_1;</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt 0.5in; text-indent: 0.5in;"><font size="2"><tt><span style="font-family: 'Times New Roman';">V_0.m_Ca</span></tt><span><font face="Times New Roman">nDoSomethingDelegate = A_1;</font></span></font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt 0.5in; text-indent: 0.5in;"><span><font size="2"><font face="Times New Roman">//add the EventSinkHelper to the arraylist</font></font></span></p>

<p class="sourcecode" style="margin: 0in 0in 0pt 0.5in; text-indent: 0.5in;"><font size="2"><font face="Times New Roman">m_aEventSinkHelpers.Add((object) V_0);<span></span></font></font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt; text-indent: 0.5in;"><font face="Times New Roman" size="2">} //end try</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt; text-indent: 0.5in;"><font face="Times New Roman" size="2">finally</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt; text-indent: 0.5in;"><font face="Times New Roman" size="2">{</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt; text-indent: 0.5in;"><font size="2"><font face="Times New Roman"><span>&nbsp;&nbsp; </span>System.Threading.Monitor::Exit(this);</font></font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt; text-indent: 0.5in;"><font face="Times New Roman" size="2">}//end finally</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="2">}// end add_CanDoSomething</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="2"></font>&nbsp;</p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="2">// We have a similar implementation for add_DoneSomething</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="2"></font>&nbsp;</p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="2">public void remove_CanDoSomething (_ILegacyComObjectEvents_CanDoSomethingEventHandler A_1)</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="2">{</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font size="2"><font face="Times New Roman"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>//declare some temporary variables</font></font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt; text-indent: 0.5in;"><font face="Times New Roman" size="2">_ILegacyComObjectEvents_SinkHelper V_2;</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt; text-indent: 0.5in;"><font face="Times New Roman" size="2">System.Threading.Monitor::Enter(this);</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt; text-indent: 0.5in;"><font face="Times New Roman" size="2">try </font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt; text-indent: 0.5in;"><font face="Times New Roman" size="2">{</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt; text-indent: 0.5in;"><font face="Times New Roman" size="2">for (each x in m_aEventSinkHelpers)</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt; text-indent: 0.5in;"><font face="Times New Roman" size="2">{</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font size="2"><font face="Times New Roman"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>if ((_ILegacyComObjectEvents_SinkHelper) x.m_CanDoSomethingDelegate == A_1)</font></font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font size="2"><font face="Times New Roman"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</font></font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font size="2"><font face="Times New Roman"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>m_aEventSinkHelpers.Remove(x); </font></font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font size="2"><font face="Times New Roman"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>V_2 = (_ILegacyComObjectEvents_SinkHelper)x;</font></font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font size="2"><font face="Times New Roman"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>m_ConnectionPoint.UnAdvise(V_2.m_dwCookie);</font></font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt 0.5in; text-indent: 0.5in;"><font size="2"><font face="Times New Roman">}<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></font></font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt; text-indent: 0.5in;"><font face="Times New Roman" size="2">}</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt; text-indent: 0.5in;"><font size="2"><font face="Times New Roman"><span>&nbsp;</span>if (m_aEventSinkHelpers is empty)</font></font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt; text-indent: 0.5in;"><font size="2"><font face="Times New Roman"><span>&nbsp;&nbsp;&nbsp; </span>System.Runtime.InteropServices.Marshal::ReleaseComObject(m_ConnectionPoint);</font></font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt; text-indent: 0.5in;"><font face="Times New Roman" size="2">}//end of try</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt; text-indent: 0.5in;"><font face="Times New Roman" size="2">finally</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt; text-indent: 0.5in;"><font face="Times New Roman" size="2">{</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt 0.5in; text-indent: 0.5in;"><font face="Times New Roman" size="2">System.Threading.Monitor::Exit(this);</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt; text-indent: 0.5in;"><font face="Times New Roman" size="2">}</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="2">}//end of remove_CanDoSomething</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="2"></font>&nbsp;</p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="2">// We have a similar implementation for remove_DoneSomething</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="2"></font>&nbsp;</p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="2">} //end of class _ILegacyComObject_EventProvider</font></p>

<p class="sourcecode" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="2"></font>&nbsp;</p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="3"></font>&nbsp;</p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="3">EventProvider does the main work for us.&nbsp;In general&nbsp;every t</font><font face="Times New Roman" size="3">ime a user adds a delegate </font></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in; text-indent: -0.25in;"><font face="Times New Roman"><span><span><font size="3">1)</font><span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><font size="3">Get the IConnectionPointer if not available from the COM server and store it in the EvenProvider. </font></font></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in; text-indent: -0.25in;"><font face="Times New Roman"><span><span><font size="3">2)</font><span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><font size="3">Create a new instance of EvenSinkHelper.</font></font></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in; text-indent: -0.25in;"><font face="Times New Roman"><span><span><font size="3">3)</font><span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><font size="3">Call Advise and give the EventSinkHelper implementation to the server.</font></font></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="3"></font>&nbsp;</p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="3">Here is something unexpected which the users will notice. </font></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="3"></font>&nbsp;</p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="3">In COM, a user may create and give one implementation of _ILegacyComObject to the server. When the event occurs the server will call both _ILegacyComObject::CanDoSomething and _ILegacyComObject::DoneSomething. Client calls only one IConnectionPoint::Advise.</font></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="3"></font>&nbsp;</p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="3">However in the managed code the user would need to do something like</font></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; color: blue; font-family: 'Courier New';"></span>&nbsp;</p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; color: blue; font-family: 'Courier New';">private</span><span style="font-size: 10pt; font-family: 'Courier New';"> <span style="color: teal;">LegacyComObject</span> m_legacyComObject;</span></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: 'Courier New';">m_legacyComObject = <span style="color: blue;">new</span> <span style="color: teal;">LegacyComObject</span>();</span></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: 'Courier New';">//add the delegate for CanDoSomething</span></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: 'Courier New';">m_legacyComObject.CanDoSomething += m_legacyComObject_CanDoSomething;</span></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: 'Courier New';">//add the delegate for DoneSomething</span></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: 'Courier New';">m_legacyComObject.DoneSomething += m_legacyComObject_DoneSomething;</span><font face="Times New Roman" size="3"> </font></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;">&nbsp;<br><font face="Times New Roman" size="3">//&nbsp;<font face="Courier New" size="2">m_legacyComObject_CanDoSomething and m_legacyComObject_DoneSomething are two functions implemented in the user class.</font></font></p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font face="Courier New" size="2"></font>&nbsp;</p>

<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font face="Times New Roman" size="3">Because we treat the two methods as two separate events&nbsp;we need to&nbsp;make two calls to _ILegacyComObjectEvents_EventProvider::add_CanDoSomething and _ILegacyComObjectEvents_EventProvider::add_DoneSomething</font></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;">
</p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font face="Times New Roman"><font size="3">Looking at the pseudo code above this would lead to two
separate connections or two separate Advise calls and which is inefficient.</font></font></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><font face="Times New Roman"><font face="Times New Roman"><font size="3">In this case, for example, in the first call we create </font><tt><span style="font-size: 10pt; font-family: 'Times New Roman';">_ILegacyComObjectEvents_SinkHelper </span></tt><font size="3">instance and call IConnectionPoint::Advise on it. Also notice that _ILegacyComObjectEvents_SinkHelper::m_DoneSomethingDelegate will remain NULL. If unmanaged COM server invokes this DoneSomething event then we&nbsp;would simply return a default value. The delegates are allowed to return only the primitive types or the value types.</font></font></font></p>

<p mce_keep="true"><font face="Times New Roman">&nbsp;</font></p>
</div>]]></content:encoded>
    </item>
  </channel>
</rss>