Skype API Protocol Example [Windows]

Share your advanced PureBasic knowledge/code with the community.
criobot
User
User
Posts: 10
Joined: Sat Dec 27, 2008 9:42 pm
Location: Bulgaria
Contact:

Skype API Protocol Example [Windows]

Post 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
Randy Walker
Addict
Addict
Posts: 989
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: Skype API Protocol Example [Windows]

Post 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.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
User avatar
idle
Always Here
Always Here
Posts: 5836
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Skype API Protocol Example [Windows]

Post 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
Windows 11, Manjaro, Raspberry Pi OS
Image
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

Re: Skype API Protocol Example [Windows]

Post by chris319 »

I fooled around with this a little. It's useless.
User avatar
Kiffi
Addict
Addict
Posts: 1485
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: Skype API Protocol Example [Windows]

Post 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
Hygge
Post Reply