Page 1 of 1

Skype API Protocol Example [Windows]

Posted: Thu Sep 08, 2011 10:38 am
by criobot
Tested on Windows Vista 32bit with Skype 5.5. Check out Skype's Public API Reference for more info about protocol versions and command compatibility.

Code: Select all

Global DiscoverSkype = RegisterWindowMessage_("SkypeControlAPIDiscover")
Global AttachSkype = RegisterWindowMessage_("SkypeControlAPIAttach")
Global SkypeHandle = 0
#Success = 0
#PendingAuthorizaion = 1
#Refused = 2
#NotAvailable = 3
#Available = $8001
Procedure ConnectSkype(hwnd)
    Protected Res
    SendMessage_(#HWND_BROADCAST, DiscoverSkype, hwnd, 0)
    ProcedureReturn res <> #False
EndProcedure

Procedure CommandSkype(hwnd, Command.s)
    cds.COPYDATASTRUCT
    cds\dwData = 0
    cds\lpData = @Command
    cds\cbData = Len(Command)
    
    If SendMessage_(SkypeHandle, #WM_COPYDATA, hwnd,  cds)
        AddGadgetItem(0, -1, Command)
    EndIf 
EndProcedure

Procedure WndProc(Handle, Message, WordParam, LongParam)
    Select Message
        Case AttachSkype
            If LongParam = #Success
                SkypeHandle = WordParam
                SetGadgetText(3, "Disconnect")
            EndIf
        Case #WM_COPYDATA
            If WordParam = SkypeHandle
                *cds.COPYDATASTRUCT = LongParam
                If *cds\lpData
                    AddGadgetItem(0, -1, PeekS(*cds\lpData))
                    SendMessage_(GadgetID(0), #WM_VSCROLL, #SB_BOTTOM, 0)
                EndIf
                
                ProcedureReturn 1
            EndIf
    EndSelect
    ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure

OpenWindow(0, 220, 0, 500, 405, "Skype API Communication",  #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_TitleBar )
SetWindowCallback(@WndProc(), 0)
ListIconGadget(0, 8, 8, 484, 324, "", 400)
StringGadget(1, 8, 340, 404, 24, "")
ButtonGadget(2, 420, 340, 72, 24, "Execute")
ButtonGadget(3, 8, 372, 112, 24, "Connect")
;CreateThread(@ConnectSkype(), WindowID(0)) ; Uncomment to enable auto-connection
AddKeyboardShortcut(0, #PB_Shortcut_Return, 0)
Repeat
    event = WaitWindowEvent()
    
    If Event = #PB_Event_Gadget
        Select EventGadget()
            Case 2
                   If GetGadgetText(1) And SkypeHandle
                        CommandSkype(WindowID(0), GetGadgetText(1))
                        SetGadgetText(1, "")
                        SetActiveGadget(1)
                    Else
                        SetActiveGadget(1)
                    EndIf
            Case 3
                If SkypeHandle
                    CommandSkype(WindowID(0), "")
                    SkypeHandle = 0
                    SetGadgetText(3, "Connect")
                Else
                    ConnectSkype(WindowID(0))
                EndIf
        EndSelect
    ElseIf Event = #PB_Event_Menu
        Select EventMenu()
                Case 0
                If GetGadgetText(1)
                    CommandSkype(WindowID(0), GetGadgetText(1))
                    SetGadgetText(1, "")
                Else
                    SetActiveGadget(1)
                EndIf
        EndSelect
    EndIf
Until event = #PB_Event_CloseWindow

Re: Skype API Protocol Example [Windows]

Posted: Mon Feb 06, 2012 4:32 am
by Randy Walker
This original post is a bit old. Wondering if anybody tried this or has any idea what it is supposed to do.

The post has no preface to explain its purpose and no comments in the listing to explain what the little code bits are doing, except for the one line that says: ''Uncomment to enable auto-connection''. I ran it with and without the line uncommented, but doesn't seem to do anything. Might be useful if it does what I think it might, and if I could get it to work.

Re: Skype API Protocol Example [Windows]

Posted: Tue Feb 07, 2012 10:22 pm
by idle
It allows you to control skype from your application, it should still be valid
On windows the skype API uses WM_COPYDATA messages to retrieve the state and data from skype
though you can also use the com wrapper Skype4com

Re: Skype API Protocol Example [Windows]

Posted: Tue May 15, 2012 4:46 am
by chris319
I fooled around with this a little. It's useless.

Re: Skype API Protocol Example [Windows]

Posted: Tue May 15, 2012 7:52 am
by Kiffi
chris319 wrote:I fooled around with this a little. It's useless.
IMO it's easier to access Skype via Skype4Com (and COMate).

Greetings ... Kiffi