Skype Integration in WPF Applications
Introduction:
Skype has become one of the prominent application for video calling, messaging etc. Interfacing skype with other application has become a necessary feature these days for application that involves the capability to chat, call etc. Skype has a good support to integrate it with web applications. But when it comes to windows application the support is very minimal. In this article I will take a walk-through by providing you one of the methods to integrate skype with WPF application using a COM interface.
You can download the source code from here,
Skype Integration
Creating a WPF Project:
- Open Visual Studio.
- Choose File -> New -> Project in the main menu. Choose "WPF Application" as project type.
- Choose a folder for your project and give it a name. Then press "OK"
Adding Skype4COM in your Application:
1.) Install Skype. You can Download Skype from the following URL:
http://www.skype.com/en/download-skype/skype-for-computer/
2.) After installing the Skype Application. Locate the COM Component Skype4Com in your machine. If you have Skype installed in C drive. It will be located in “C:\Program Files (x86)\Common Files\Skype”
3.) After Register the Component to Windows Machine using the following steps*** ***
For 32-bits OS:
- copy Skype4COM.dll to your c:\windows\system32 folder
- Open an Elevated CMD.exe (right click cmd.exe and choose 'Run as Administrator')
- Set current Path to C:\Windows\System32
- execute regsvr32.exe Skype4COM.dll
For 64-bits OS:
- Copy** Skype4COM.dll to your c:\windows\SysWOW64 folder**
- Open an Elevated CMD.exe (right click cmd.exe and choose 'Run as Administrator')
- Set current Path to C:\Windows\SysWOW64
- execute regsvr32.exe Skype4COM.dll
4.) Now right click the project and select Add Reference. In the References section you will see the SKYPE4COMLib Missing. Now Right click “References -> Add Reference”
5.) In the Reference Manager Dialog. Under “COM -> Type Libraries” Section you can see Skype component registered. Select the ***“Skype4Com 1.0 Type Library” ***and Click OK.
Code Snippets:
Creating a Instance of Skype
public Skype Skype
{
get;
set;
}
Skype = new SKYPE4COMLib.Skype();
Skype.Attach(7, false);
**Log In into Skype Client:
**
/* Starts the Skype Client. If the User is not Logged in, it prompts the Login Dialog*/
Skype.Client.Start();
/* you can also open the authorization dialog by passing the username */
Skype.Client.OpenAuthorizationDialog("username");
Get the List of Friends:
public List<Friend> GetFriends()
{
var friends = new List<Friend>();
var users = Skype.Friends.OfType<SKYPE4COMLib.User>();
foreach (var user in users)
{
var avatarSavePath = @"C:\Skype\Images\" + user.Handle + ".jpg";
SaveSkypeAvatarToDisk(user.Handle, avatarSavePath);
friends.Add(new Friend { About = user.About, Aliases = user.Aliases, Birthday = user.Birthday, City = user.City, Country = user.Country, DisplayName = user.DisplayName, FullName = user.FullName, Handle = user.Handle, MoodText = user.MoodText, NumberOfAuthBuddies = user.NumberOfAuthBuddies, OnlineStatus = user.OnlineStatus, RichMoodText = user.RichMoodText, Sex = user.Sex, ProfilePicture = new ProfilePicture { UserName = user.Handle, ProfilePicturePath = avatarSavePath } });
}
return friends;
}
Saving the Avatar Image of the User:
void SaveSkypeAvatarToDisk(string userHandle, string rootedPathFileName)
{
if (!System.IO.Path.IsPathRooted(rootedPathFileName))
throw new ArgumentException("Filename does not contain full path!", "rootedPathFileName");
if (!".jpg".Equals(System.IO.Path.GetExtension(rootedPathFileName)))
throw new ArgumentException("Filename does not represent jpg file!", "rootedPathFileName");
SKYPE4COMLib.Command command0 = new SKYPE4COMLib.Command();
command0.Command = string.Format("GET USER {0} Avatar 1 {1}", userHandle, rootedPathFileName);
Skype.SendCommand(command0);
}
Friend Class:
public class Friend : INotifyPropertyChanged
{
private string about;
private string aliases;
private DateTime birthday;
private string city;
private string country;
private string displayName;
private string fullName;
private string handle;
private string moodText;
private int numberOfAuthBuddies;
private TOnlineStatus onlineStatus;
private ProfilePicture profilePicture;
private string richMoodText;
private TUserSex sex;
public string About
{
get
{
return about;
}
set
{
about = value;
OnPropertyChanged("About");
}
}
public string Aliases
{
get
{
return aliases;
}
set
{
aliases = value;
OnPropertyChanged("Aliases");
}
}
public DateTime Birthday
{
get
{
return birthday;
}
set
{
birthday = value;
OnPropertyChanged("Birthday");
}
}
public string City
{
get
{
return city;
}
set
{
city = value;
OnPropertyChanged("City");
}
}
public string Country
{
get
{
return country;
}
set
{
country = value;
OnPropertyChanged("Country");
}
}
public string DisplayName
{
get
{
return displayName;
}
set
{
displayName = value;
OnPropertyChanged("DisplayName");
}
}
public string FullName
{
get
{
return fullName;
}
set
{
fullName = value;
OnPropertyChanged("FullName");
}
}
public string Handle
{
get
{
return handle;
}
set
{
handle = value;
OnPropertyChanged("Handle");
}
}
public string MoodText
{
get
{
return moodText;
}
set
{
moodText = value;
OnPropertyChanged("MoodText");
}
}
public int NumberOfAuthBuddies
{
get
{
return numberOfAuthBuddies;
}
set
{
numberOfAuthBuddies = value;
OnPropertyChanged("NumberOfAuthBuddies");
}
}
public TOnlineStatus OnlineStatus
{
get
{
return onlineStatus;
}
set
{
onlineStatus = value;
OnPropertyChanged("OnlineStatus");
}
}
public ProfilePicture ProfilePicture
{
get
{
return profilePicture;
}
set
{
profilePicture = value;
OnPropertyChanged("ProfilePicture");
}
}
public string RichMoodText
{
get
{
return richMoodText;
}
set
{
richMoodText = value;
OnPropertyChanged("RichMoodText");
}
}
public TUserSex Sex
{
get
{
return sex;
}
set
{
sex = value;
OnPropertyChanged("Sex");
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string propertyName)
{
var handler = this.PropertyChanged;
if (handler != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
**Controlling Skype Client:
**
/* Starts the Skype Client. If the User is not Logged in, it prompts the Login Dialog*/
Skype.Client.Start();
/* Shutdowns the Skype Client */
Skype.Client.Shutdown();
/* Set the Focus of the Skype Application */
Skype.Client.Focus();
/* Checks whether skype is running */
Skype.Client.IsRunning
**Controlling Skype Dialogs: (Just listed important dialogs still a lot exist in the Skype4COM)
**
/* opens the Chat Windows for the friend */
Skype.Client.OpenMessageDialog("friend username");
/* Opens the Conference dialog */
Skype.Client.OpenConferenceDialog();
/* opens the Add contact dialog */
Skype.Client.OpenAddContactDialog();
/* Opens call history tab */
Skype.Client.OpenCallHistoryTab();
/* opens contacts tab */
Skype.Client.OpenContactsTab();
/* opens Authorization dialog for the given username */
Skype.Client.OpenAuthorizationDialog("username");
/* Open Blocked users dialog */
Skype.Client.OpenBlockedUsersDialog();
/* opens the Dialpad */
Skype.Client.OpenDialpadTab();
/* opens Imports the Contacts Wizard */
Skype.Client.OpenImportContactsWizard();
/* opens Profile dialog for the current logged in user */
Skype.Client.OpenProfileDialog();
/* Opens Search dialog */
Skype.Client.OpenSearchDialog();
You can download the sample Code from the following link
Skype Integration