Michael Wolf

{Binding ME}

20091120 Friday November 20, 2009

Silverlight 4 dials in skype

One of the pains in silverlight 3 out of browser was the strict sandbox that was put in place. Although well meaning, this put a heavy restriction on the type of rich desktop like experiences we could produce. Just as in the api limitations in Adobe Air, there were and are solutions which involve local socket services (as discussed in this blog entry last year: http://www.cynergysystems.com/blogs/page/michaelwolf?entry=breaking_the_sandbox_in_silverlight ). However now in silverlight 4 we will have a much better solution, definitely not perfect but better. Firstly as mentioned in our drag and drop post (http://www.cynergysystems.com/blogs/page/michaelwolf?entry=silverlight_4_drag_from_desktop ) you can drag files directly into the out of browser window, which gets us closer. However the biggest improvement here is the inclusion of elevated privileges, which allows you to get access to the local file systems at a pretty broad level, but more importantly access to locally registered com objects. This means direct access to integrate with things like word or excel, like you will see in most demos, but also the huge community of com objects like skype.

When I first saw this feature, I remembered that back in the bad old silverlight 1.1 days I investigated using Skype to make phone calls via the java script bridge. What I found was that skype makes available a very rich com api known as SKype4Com. So while on the plane back from PDC09 I set out at integrating this into Silverlight 4. The screencast below shows the results of opening, changing focus of, and then dialing the skype test user using the Skype4Com api and the Silverlight 4 elevated privileges support.



In order to utilize the Skype4Com api with in silverlight 4, there are a couple steps you need to follow to begin:

  1. First you will need to register the dll with windows , good old regrv32 does the trick
  2. Next you will need to ensure that your project references the Microsoft.Csharp dll which is available in the silverlight SDK, this gives you access to the Dynamic keyword (aka Dim for all you old VB developers).
  3. Next you will need to go inbto your silverlight project properties and ensure the silverlight app has oob enabled
  4. Lastly you will need to go into out of browser properties and click the require elevated privileges checkbox. This will allow your code to hit the registered dll, and will also show the user the following install message.


After this is all set your ready to start programming like its 1999. No really… although the com inerop functionality is extremely powerful, the dev model is not the .net world you have come to love. This is one time in the microsoft xaml world where remembering what cdonts is, is a benefit to you now. That’s because com inerop is very similar to the asp classic days where we would create a cdonts object to send mail or createobject() to throw a message into msmq. When working at this level you will not have intellisense we all love, and debugging will become more difficult. However as the saying goes "with great power comes great responsibility". So for example in the following code snippet we will create a dynamic object, and start working directly with the Skype4Com api.



Pretty simple, lines of code wise. The difficulty comes from the lack of discoverability via intellisense or reflector. Which as a developer will put you at the whim of the dll developer. Luckily Skype releases great docs (https://developer.skype.com/Docs/Skype4COM) as does the Microsoft Office team (http://msdn.microsoft.com/en-us/library/bb726434.aspx).

All in all though were very happy with this solution to bridge the sandbox divide. So many of our customers are looking for this type of integration particularly with products like excel or outlook that we had previously had to find less than desirable approaches to resolve. Even with the com development model, this is still 500X easier and more stable than the alternatives, and will open allot of doors and great rich desktop experiences. To learn more about this functionality check out the great session by Joe Stegman at pdc from this week http://microsoftpdc.com/Sessions/CL20

Posted by michaelwolf | Nov 20 2009, 09:11:31 AM EST
XML