|
|
YOUR FEEDBACK
Did you read today's front page stories & breaking news?
SYS-CON.TV SYS-CON.TV WEBCASTS |
POWERBUILDER LINKS YOU MUST CLICK ON VOIP
Tablet PC Programming
Adding VoIP capabilities to your PowerBuilder application using Skype
By: Deanne M. Chance
Mar. 26, 2006 10:00 AM
Digg This!
Page 1 of 2
next page »
We begin this article by answering a few questions. Namely, what is VoIP? What is Skype? And why would you want to integrate these capabilities into your PowerBuilder applications?
For starters, VoIP is an acronym for Voice over Internet Protocol. In a nutshell, it allows you to make a call via your computer through an Internet connection. We won't get into the specifics of how it works but, if you are interested in learning more, I would encourage you to check out http://computer.howstuffworks.com/ip-telephony.htm. The other component is Skype (see Figure 1), which is a program that enables you to make calls over the Internet to anyone else who has it. It's free and easy to use and works with most computers. It also has the capability of making inbound and outbound calls to and from landlines (although there is a charge of about 2¢ a minute). To try it out, you can download it from www.skype.com/download/. We'll cover three of the methods to initiate a basic phone call. They are:
To complete this exercise you'll need the following items.
That being said, let's go step-by-step to see how to create a simple but functional example that will illustrate the basic concepts you'll need to know (see Figure 2).
SETUP
METHOD 1
//adjust our url to make an outbound phone call Run your project and click on the link. You have just made your first VoIP call.
METHOD 2
//another easy way to make a phone call You have just made your second VoIP call. Easy enough, but suppose you wanted to do more than just make a simple phone call? Here is where the Active-X control can help us. This control is loaded with just about anything you would want to do. You can check out the documentation for all its methods and properties. The only thing you may not be used to is the format of the documentation, which may be somewhat intimidating to the non-C++ crowd. It's generated from IDL files and may be a little hard to follow until you get used to it. The nice thing though is they have all their examples in VBScript, which is close enough to PowerScript to get a good grasp on the code examples. This control is free for educational or non-commercial uses. However, if you want to distribute it with your applications, it will set you back about $50. One word of caution: to locate a Skype user, they use a property called Handle. This of course is a problem for us PB folks since that's a reserved word. In general, I might note, there are also some other downsides to consider when using a third-party Active-X control. They are:
Interface directly with the Skype API. For this one, we'll have to do a little work. Before we start though, it might be useful to explain a little bit about how you go about communicating with the API in the first place. There are no DLLs, rather, it's a message-based system that utilizes the Microsoft Messaging Services. If you're not familiar with it, check out this site: http://msdn.microsoft.com/library/default.asp?url=/library/ en-us/winui/winui/WindowsUserInterface/Windowing/MessagesandMessageQueues.asp. To begin, we'll need to initiate communication with the Skype server by sending out a "discovery" message. This is shown in Listing 1. Here we're using the Win32 API call RegisterWindowMessage(). This tells Windows to return a unique message identifier for the string we pass in. In this case, we are interested in the two messages SkypeControlAPIDiscover and SkypeControlAPIAttach. We'll use the SkypeControlAPIAttach message ID to determine if the Skype Server is ready to process our commands. To actually send the message use another Win32 API call, SendMessage(). This does the actual work of sending the discovery message. The constant WM_BROADCAST_MESSAGE tells Windows to send the message to all open windows. Why send the message to all windows? If you look at the prototype of SendMessage(), it takes a handle to a window as one of its parameters. However, since we don't know the handle of the Skype server yet, we'll need to send a message to all windows. Later on, Skype will return its handle back in the Message.WordParm. Save this value and use it for subsequent calls to SendMessage(). The prototypes for the API calls are listed below:
Perhaps a look at the code in the "other" event used to process the discovery message sent back by Skype would be useful at this point. For that, refer to Listing 2. Note, for simplicity sake, we are not using an invisible window as suggested earlier. This may become apparent in your testing in that Skype may occasionally not respond to your commands. This is particularly true if you try to run your project within the IDE. This is because if Skype does not receive a reply within one second, it times out. Given that Skype is ready to start receiving commands, we need a way to send them. For that see Listing 3. Note that we have written a generic function that can send any Skype command. Two points are important here: we are using SendMessage() to communicate with Skype and the message we are sending is defined as WM_COPY_DATA_MESSAGE. Both are defined in the MSDN library. If you look at the code, you can see that we are populating the copy data structure with the message we wish to send. There are two important parameters: the size of the data as well as a pointer to the data. Note: when taking the size of the data, we must add one because the Len() function does not take into account the required null terminating character. What about that pointer? That's a little tricky. PowerBuilder manages application memory like Java and C#, which hides the complexities of pointers from us. Thus, we have this code:
Here you can see we are using two Win32 API calls for getting a pointer to the command string we are going to send. Their prototypes are shown below:
Page 1 of 2 next page »
PBDJ LATEST STORIES . . .
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
|
SYS-CON FEATURED WHITEPAPERS MOST READ THIS WEEK BREAKING POWERBUILDER / SYBASE NEWS
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||