📜 ⬆️ ⬇️

Using Skype API in C ++

Not so long ago, I needed to write an application that would automatically send a message via Skype to a specific user who is in the contact list. The task was not much more difficult, but that is not the point. I decided to write a small article on the use of Skype API.

Everyone knows that Skype has its own API, and for different languages. I wanted to start the descriptions with Skype4COM for C ++.
Download Skype4COM from the official site .
The archive contains three files:

We need proper Skype4COM.dll .

Hello world for Skype


For the first example, I decided to take an example from the Skype site, which displays the version of the current Skype client.
#import "Skype4COM.dll"

int _tmain( int argc, _TCHAR* argv[]) {
// COM
CoInitialize(NULL);

// Skype
SKYPE4COMLib::ISkypePtr pSkype(__uuidof(SKYPE4COMLib::Skype));

// Skype API
pSkype->Attach(6,VARIANT_TRUE);

//
_bstr_t bstrSkypeVersion = pSkype->GetVersion();
printf( "Skype client version %s\n" , ( char *)bstrSkypeVersion);

// COM ""
_bstr_t bstrWrapperVersion = pSkype->GetApiWrapperVersion();
printf( "COM wrapper version %s\n" , ( char *)bstrWrapperVersion);

//
pSkype = NULL;
CoUninitialize();

return 0;
}


In general, everything is simple and clear. The truth is there is not a lot of moments not pleasant, as always associated with security, which is on the line:
pSkype->Attach(6, VARIANT_TRUE);

Skype request permission to use Skype resources by our application. From the security side, it is right, but there is a minor way around, but it’s not about the current post))))

Send a message to the user from the contact list


We continue the set of banal examples, now we’ll actually deal with sending a message:
#import "Skype4COM.dll"
using namespace SKYPE4COMLib;

int _tmain( int argc, _TCHAR* argv[]) {
CoInitialize(NULL);
ISkypePtr pSkype(__uuidof(Skype));
pSkype->Attach(6,VARIANT_TRUE);

IChatMessage *message;
message = pSkype->SendMessage(_bstr_t(L "user_name" ), _bstr_t(L "" ));
printf( "%s sent message" , ( char *)message->FromHandle);

pSkype = NULL;
CoUninitialize();
return 0;
}


In order to dial a user, you need to call the PlaceCall method:
ICallPtr pCall = pSkype->PlaceCall(_bstr_t(L"user_name"), L"", L"", L"");

Get a list of contacts


IUserCollectionPtr contactList = pSkype->GetFriends();
for ( int i = 1; i <= contactList->GetCount(); i++) {
_bstr_t bstrHandle = contactList->GetItem(i)->GetHandle();
_bstr_t bstrFullname = contactList->GetItem(i)->GetFullName();
printf( "Friend login %s and name %s \n" , ( char *)bstrHandle, ( char *)bstrFullname);
}


Sources
')
If the topic is interesting, I can write more interesting examples of using Skype4COM ...

Source: https://habr.com/ru/post/72059/


All Articles