比較需要注意的是,由於Skype4Com下載下來的壓縮檔裡面的說明檔Skype4Com.chm,裡面所說到的Class name, Function name都不能直接用,因為Skype4Com.dll已經透過BCB封裝過了,所以必須按照BCB編過後的方式去處理才行,封裝過後的檔案在$(BCB)/Imports/裡,有四個檔案,包括SKYPE4COMLib_OCX與SKYPE4COMLib_TLB的.cpp與.h檔。以下的範例有提到,請參考。
#include <vcl.h>範例檔下載連結
#include <iostream>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "SKYPE4COMLib_OCX"
#pragma resource "*.dfm"
TForm1 *Form1;
using namespace std;
// 這個程式是用來測試Skype4Com的一些功能
// (1) 要執行這個程式 首先要將$(BCB)/Imports/加入 Include Path
// #include "SKYPE4COMLib_OCX.h"
// (2) 需要新增以下的元件:
// TListBox *ListBox1;
// TButton *Button1;
// TButton *Button2;
// TButton *Button3;
// TMemo *Memo1;
// (3) 需要額外宣告變數:
// TSkype * mSkype;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
mSkype = new TSkype(Owner);
mSkype->Attach(5,false);
// test if Skype is running, if not, start it;
if( !mSkype->Client->IsRunning )
mSkype->Client->Start(false,false);
// 1st parameter - start Skype in minimized state
// 2nd parameter - show splash screen
// Get the count of Friends
int count = mSkype->Friends->get_Count();
// Add Friend list to Memo
for( int i=1 ; i<count ; i++ )// start index from 1 !!!
this->ListBox1->Items->Add( mSkype->Friends->get_Item(i)->get_Handle() );
// 設置處理Skype Event的function
mSkype->OnCallStatus = OnCallStatus;
mSkype->OnMessageStatus = OnMessageStatus;
}
// @target :
// Create 一個Chat Object
// 並傳送訊息給 Friend "falldog7_test"
void __fastcall TForm1::Button1Click(TObject *Sender)
{
IChatPtr chat;
chat = mSkype->CreateChatWith( L"falldog7_test" );
//開啟對話視窗
chat->OpenWindow();
//傳送訊息過去給falldog7_test
chat->SendMessage( L"Fuck You!" );
chat->Disband();
}
// @target :
// 撥電話給 好友 : "falldog7_test"
void __fastcall TForm1::Button2Click(TObject *Sender)
{
ICallPtr call = mSkype->PlaceCall(L"falldog7_test",L"",L"",L"");
}
// @target :
// 取出所有正在通話的 Call ,並將其所有的OutputDevice導至(1) Soundcard (2) File
void __fastcall TForm1::Button3Click(TObject *Sender)
{
wstring path = L"D:\\WorkRoom\\project-中文也行\\test.wav";
ICallCollectionPtr call_list = mSkype->ActiveCalls;
for( int i=1; i<=call_list->Count ; i++ ){
call_list->get_Item(i)->set_OutputDevice( callIoDeviceTypeSoundcard, L"default" );
call_list->get_Item(i)->set_OutputDevice( callIoDeviceTypeFile, const_cast<wchar_t*>(path.c_str()) );
this->Memo1->Lines->Add( "OutputDevice direct success!" );
}
}
// Skype4Com的Event
// 在Skype4Com.chm中定義的 Class : _SkypeEvents 裡面
// HRESULT CallStatus ([in] ICall *pCall,[in] TCallStatus Status)
// This event is caused by a change in call status.
// 經由BCB處理過後的header檔,定義在 $(BCB)/Imports/SKYPE4COMLib_OCX.h 88行
//
// @TCallStatus 的定義在Skype4Com.chm 與 SKYPE4COMLib_TLB.h中都找得到
// @target : 當有人Call我時(Ringing) 就直接接起此通Call
void __fastcall TForm1::OnCallStatus( TObject *Sender, ICall* _call/*[in]*/, TCallStatus Status/*[in]*/)
{
if( Status == clsRinging ){
// ShowMessage("A Call is Rining");
_call->Answer();
}
}
// Skype4Com的Event
// 在Skype4Com.chm中定義的 Class : _SkypeEvents 裡面
// HRESULT MessageStatus ([in] IChatMessage *pMessage,[in] TChatMessageStatus Status)
// This event is caused by a change in chat message status.
// 經由BCB處理過後的header檔,定義在 $(BCB)/Imports/SKYPE4COMLib_OCX.h 93行
//
// @TChatMessageStatus 的定義在Skype4Com.chm 與 SKYPE4COMLib_TLB.h中都找得到
// @target : 當有人傳訊息給我時,就在Memo1上印出訊息
void __fastcall TForm1::OnMessageStatus( TObject *Sender, IChatMessage* pMessage/*[in]*/, TChatMessageStatus Status/*[in]*/)
{
this->Memo1->Lines->Add( AnsiString("From : ")+ pMessage->FromHandle );
if( Status == cmsReceived ){
this->Memo1->Lines->Add( AnsiString("Msg : ")+ pMessage->Body );
}
}