Τετάρτη, 24 Φεβρουαρίου 2010 - Δημοσιεύσεις

Creating a Skype add-on using .NET - Part 1

Skype provides pretty rich API for us developers to create add-ons that can customize it's behaviour. There are a number of ways to use this API and access Skype functionality programmatically. Skype4COM is one of these ways and is the recommended one if you want to create your add-on using .NET. Skype4COM is a wrapper dll that provides Skype functionality into the COM world, therefore also to the .NET world, since .NET can use COM dll libraries.

Skype4COM.dll is located into the Program Files\Common\Skype folder (or Program Files (x86)\Common\Skype in case of x64 version of Windows). It is installed (and registered) there if you install Skype with Extras enabled (this is an option of one of the steps of Skype installation). Once done, you can add a reference to it from your .NET project. Simply right click on your project in the Visual Studio solution explorer, select Add Reference and then click on the COM tab. Skype4COM should be in the list populated there.

Example
Here is a simple (self descriptive) example of accessing Skype functionality from your C# code:

SkypeClass skype = new SkypeClass();
Debug.WriteLine(skype.Friends.Count);

Note that once new SkypeClass() is executed, Skype will warn the end-user that some process is trying to access it. End-user must allow your process to access Skype, else you will get an exception.

x64 operating systems!
Here is something you should take care of! I missed this step and in the beginning and spend quite some time figuring out why SkypeClass fails to be initialized! Since Skype4COM is a x86 (a.k.a. 32 bit) library, your add-in should also be x86 in order to be able to use it. In order to configure your project to produce a x86 executable you need to use the configuration manager of Visual Studio. Click on Build menu and then Configuration Manager. In Active solution platform drop down list, select <New>... and on the dialog that opens select x86 as platform. If you miss performing this steps you will notice the problem only on machines with x64 operating system. If operating system is x86, your .NET executable will run as x86 process anyway so it will succeed in instantiating Skype4COM dll.

Resources
Skype4COM Reference (all things you can do with Skype4COM)
Examples (a number of useful examples in many languages)
Forums (unfortunately you will not find prompt help there. most of the threads remain unanswered for days)

Permalink | Leave a comment  »