|Written by Harry Fairhead|
|Sunday, 12 July 2009|
Page 1 of 5
Skype is one of the easiest to use VoIP (Voice over IP) services mainly because all you need is a broadband connection and some free-to-download software. From a programmer’s point of view it also has the advantage of having an easy-to-use API. This is delivered to the Windows programmer in two forms – an ActiveX control and a raw API. The ActiveX control is useful but is limited. In particular it doesn’t allow access to the audio streams which makes it difficult to write programs that act as answering machines or play the contents of an audio file to someone.
Being able to handle the audio during a Skype “live” call or in voicemail leads to all sorts of exciting projects and this is what makes it worth mastering the full API. Fortunately it isn’t as difficult as the documentation and available examples might lead you to believe. Despite the fact that there is very little information on how to use the Skype API from a managed language such as C#, it’s all just a matter of message passing.
A key fact about Windows that is rapidly being hidden by sophisticated programming systems such as .NET is that Windows is a message passing operating system. All of the controls, buttons, textboxes and so on that you see are also just specialised windows and these communicate with one another by sending messages. For example, when you click a button the button generates a message which is passed to its parent window which can then perform some action in response to the click. Languages such as C# use an alternative concept of events to do the same sort of thing but events are built on top of messages. The good news is that .NET provides good access to the message processing machinery of an application and you can use the Windows API to send messages to other applications.
The next question is what has the Windows message passing system got to do with Skype and its API? The answer is that rather than use COM or some other more sophisticated mechanism the API works by passing custom messages. To control Skype your application has to send particular messages containing commands in text form and Skype sends messages back to your application that give its current status and the progress of any action you have asked it to perform. This mechanism is both simple and fundamental but it compares well to more sophisticated interfaces such as COM.
Connecting to Skype
Before you start to make use of Skype you should check that it is installed and running. This is a matter of checking the registry and letting the user know that your application doesn’t work without Skype if it isn’t found. For the sake of simplicity we will assume that Skype is installed, running and working properly – check you can make a test call before proceeding.
Given Skype is running the first task is to make a connection between it and our application. To do this we need to use two custom messages that Skype registers with the system when it is first installed – one to make first contact with Skype and the second to make the actual connection. Any application can register a custom message and given that a message is identified by a 16-bit value there has to be a way to stop two applications registering the same code. The solution is that Windows assigns a free message code when a custom message is registered. This means that the custom message will have different codes on different machines. To find out what code is actually in use you have to ask Windows to tell you what the custom message corresponds to using the RegisterWindowMessage API call. If the message isn’t already registered then Windows assigns a new unique code. If the message is already registered by another application it returns the code previously allocated.
|Last Updated ( Monday, 27 July 2009 )|