余小章 @ 大內聖殿
祕訣無它, 唯勤而已, by 余小章

导航

 

1.安裝Skype,http://skype.pchome.com.tw/

2.下載 Skype4COM ,http://developer.skype.com/accessories

image

3.解壓縮後註冊Skype4COM.dll,在檔案根目錄下建立reg.bat檔案並加入以下內容,存檔後雙擊

regsvr32 /s Skype4COM.Dll

image

4.註冊成功後就可以在VS裡面引用此元件,若沒有在此畫面出現Skype4COM1.0TypeLibrary. 元件表示沒有註冊成功

image

以下內容出自~http://msdn.microsoft.com/zh-tw/library/hsy826az%28VS.80%29.aspx

引用成功後VS會自動建立 Interop 組件,這是一個特別的 .NET 組件,內含可定義 COM 型別的中繼資料 (Metadata),而且該組件還能讓 .NET 編譯器 (Compiler) 解析 COM 物件的呼叫。

也就是說,VS會幫你在bin資料夾裡產生一個Interop.SKYPE4COMLib.dll的Metadata對應組件,版本都是1.0.0.0,這個組件是解析了當時引用的元件版本,倘若你直接引用這個特殊組件,未來Skype4COM.dll更新的話,你所引用的Interop.SKYPE4COMLib.dll並沒有未來版本的新功能,得必須重新產生Interop.SKYPE4COMLib.dll對應檔,正確的做法是引用Skype4COM.dll而不是引用.NET產生出來的Interop.SKYPE4COMLib.dll

image image

5.購買Skype簡訊點數

6.當你在Win7底下引用成功後,建置方案時在VS裡會出現了以下訊息:

image

可以試著把平台改成AnyCUP,則可順利建置

image

7.Skype API其實就是利用SendMessage API來控制Skype軟體,當外部程式要控制Skype軟體時,第一次會有下列訊息出現,必須要按下允許存取才能順利操作。

image


前置作業完成後,再來就可以在程式碼裡引用這些API了

傳送手機簡訊:

這兩個事件SmsTargetStatusChangedEventHandler及SmsMessageStatusChangedEventHandler可以好好觀察一下,用來確認簡訊發送狀況

private void button5_Click(object sender, EventArgs e)
{
    SKYPE4COMLib.SkypeClass skype = new SkypeClass();
    skype.SmsTargetStatusChanged += new _ISkypeEvents_SmsTargetStatusChangedEventHandler(skype_SmsTargetStatusChanged);
    skype.SmsMessageStatusChanged += new _ISkypeEvents_SmsMessageStatusChangedEventHandler(skype_SmsMessageStatusChanged);
    SmsMessage message = skype.CreateSms(TSmsMessageType.smsMessageTypeOutgoing, "輸入電話號碼");
    message.Body = "測試內容";
    message.Send();
}

void skype_SmsMessageStatusChanged(SmsMessage pMessage, TSmsMessageStatus Status)
{
    switch (Status)
    {
        case TSmsMessageStatus.smsMessageStatusComposing:
            break;
        case TSmsMessageStatus.smsMessageStatusDelivered:
            break;
        case TSmsMessageStatus.smsMessageStatusFailed:
            break;
        case TSmsMessageStatus.smsMessageStatusRead:
            break;
        case TSmsMessageStatus.smsMessageStatusReceived:
            break;
        case TSmsMessageStatus.smsMessageStatusSendingToServer:
            break;
        case TSmsMessageStatus.smsMessageStatusSentToServer:
            break;
        case TSmsMessageStatus.smsMessageStatusSomeTargetsFailed:
            break;
        case TSmsMessageStatus.smsMessageStatusUnknown:
            break;
        default:
            break;
    }
}

void skype_SmsTargetStatusChanged(SmsTarget pTarget, TSmsTargetStatus Status)
{
    switch (Status)
    {
        case TSmsTargetStatus.smsTargetStatusAcceptable:
            break;
        case TSmsTargetStatus.smsTargetStatusAnalyzing:
            break;
        case TSmsTargetStatus.smsTargetStatusDeliveryFailed:
            break;
        case TSmsTargetStatus.smsTargetStatusDeliveryPending:
            break;
        case TSmsTargetStatus.smsTargetStatusDeliverySuccessful:
            break;
        case TSmsTargetStatus.smsTargetStatusNotRoutable:
            break;
        case TSmsTargetStatus.smsTargetStatusUndefined:
            break;
        case TSmsTargetStatus.smsTargetStatusUnknown:
            break;
        default:
            break;
    }
}


發送聊天訊息

private void button6_Click(object sender, EventArgs e)
{
    SKYPE4COMLib.SkypeClass skype = new SkypeClass();
    skype.MessageStatus += new _ISkypeEvents_MessageStatusEventHandler(skype_MessageStatus);
    ChatMessage message = skype.SendMessage("帳號", "內容");
}

void skype_MessageStatus(ChatMessage pMessage, TChatMessageStatus Status)
{
    switch (Status)
    {
        case TChatMessageStatus.cmsRead:
            break;
        case TChatMessageStatus.cmsReceived:
            break;
        case TChatMessageStatus.cmsSending:
            break;
        case TChatMessageStatus.cmsSent:
            break;
        case TChatMessageStatus.cmsUnknown:
            break;
        default:
            break;
    }
}


撥打電話

private void button7_Click(object sender, EventArgs e)
{
    SkypeClass skype = new SkypeClass();
    CommandClass cmd = new CommandClass();
    skype._ISkypeEvents_Event_Command += new _ISkypeEvents_CommandEventHandler(skype__ISkypeEvents_Event_Command);
    cmd.Command = "OPEN IM " + "撥號";//打開Skype視窗;
    skype.SendCommand(cmd);

    cmd.Command = "CALL " + "撥號";//撥號
    skype.SendCommand(cmd);
}

void skype__ISkypeEvents_Event_Command(Command pCommand)
{
}

image


取消撥號
private void button8_Click(object sender, EventArgs e)
 {
     SkypeClass skype = new SkypeClass();
     CommandClass cmd = new CommandClass();
     cmd.Command = "SEARCH ACTIVECALLS";//搜尋ID
     skype.SendCommand(cmd);

     int id = skype.ActiveCalls[1].Id;
     cmd.Command = "SET CALL " + id + " STATUS FINISHED";//根據ID掛斷電話
     skype.SendCommand(cmd);
 }
posted on 2011-12-27 15:29  余小章  阅读(1812)  评论(1编辑  收藏  举报