YOUR FEEDBACK
Steve Jobs Not Dying, Press Figures
iPhone News Desk wrote: Apple telling the press that the state of its CEO'...
AJAXWorld RIA Conference
$300 Savings Expire July 25
Register Today and SAVE!


2007 West
GOLD SPONSORS:
Active Endpoints
Your SOA Needs BPEL for Orchestration
BEA
Virtualized SOA: Adaptive Infrastructure for Demanding Applications
Nexaweb
Overcoming Bandwidth Challenges with Nexaweb
TIBCO
What is Service Virtualization?
SILVER SPONSORS:
WSO2
Using Web Services Technologies and FOSS Solutions
Click For 2007 East
Event Webcasts

2008 East
PLATINUM SPONSORS:
Appcelerator
Think Fast: Accelerate AJAX Development with Appcelerator
GOLD SPONSORS:
DreamFace Interactive
The Ultimate Framework for Creating Personalized Web 2.0 Mashups
ICEsoft
AJAX and Social Computing for the Enterprise
Kaazing
Enterprise Comet: Real–Time, Real–Time, or Real–Time Web 2.0?
Nexaweb
Now Playing: Desktop Apps in the Browser!
Sun
jMaki as an AJAX Mashup Framework
POWER PANELS:
The Business Value
of RIAs
What Lies Beyond AJAX?
KEYNOTES:
Douglas Crockford
Can We Fix the Web?
Anthony Franco
2008: The Year of the RIA
Click For 2007 Event Webcasts
SYS-CON.TV
POWERBUILDER LINKS YOU MUST CLICK ON


Tablet PC Programming
Adding VoIP capabilities to your PowerBuilder application using Skype

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?

We will begin with the latter. Imagine that you are a field service worker armed with a tablet PC with a wireless broadband connection and you want to call your next client from your appointment list. You could just use your cell phone, but that would require you to look up and dial the number independent of your application. However, imagine an integrated solution whereby you could click on the next appointment and have your application automatically dial that contact. This is where Skype and VoIP come in. By integrating VoIP capabilities into our PowerBuilder applications, it's now possible to call someone directly from within our programs. This article will show you how.

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:

  1. linkto
  2. SkypeX ActiveX control
  3. Native Skype API
The first two methods are trivial so we won't spend a lot of time on those. Rather, we will spend the majority of our time examining the core Skype API and how to use it.

To complete this exercise you'll need the following items.

After reading this article you should be able to make a simple phone call using any of the aforementioned methods. We'll also briefly cover the Microsoft Messaging Service and how it's used as a transport mechanism for the Windows Skype API implementation. In addition, for the Skype API you can learn a little bit about some of the commands available by looking here: http://share.skype.com/sites/devzone/2006/01/ api_reference_for_skype_20_bet.html#COMMANDS.

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
Create a main window and drop the following controls on it: a multi-line edit, a static hyperlink, a single line edit, two command buttons, and a SkypeX ActiveX Control.

METHOD 1
Code for the linkto method by adding the following code to the clicked event of the static hyperlink.

//adjust our url to make an outbound phone call
shl_call.url = 'CALLTO:' + sle_phonenumber.Text

Run your project and click on the link. You have just made your first VoIP call.

METHOD 2
Code for the Active-X method by adding the following code to the clicked event of one of your command buttons.

//another easy way to make a phone call
ole_skype.object.PlaceCall(sle_phonenumber.Text)

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:

  1. It may not be updated in a timely manner when the API changes.
  2. You have to pay for it.
  3. You have to deploy it.
METHOD 3
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:

  • Function long RegisterWindowMessage(string msg) library "user32.dll" Alias for "RegisterWindowMessageA"
  • Function long SendMessage( long hWnd, ulong Msg, ulong wParam, long lParam ) Library "user32" Alias For "SendMessageA"
The next question is: How do we receive messages from Skype? The answer is in the PowerBuilder "other" event. The "other" event is used to capture any Windows messages that are not already caught by PowerBuilder. A little-appreciated fact about this event is that it slows down all processing for that window. Say you used an application window, that would definitely have a performance impact since it would be busy processing every Windows message not already caught by PowerBuilder. Thus an improvement might be to have the Skype handler in a dedicated window that's kept invisible. That would have the least effect on the overall application performance.

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:


//trick for getting ptr to string
ll_StringPointer = LocalAlloc( 0, Len( ls_Buffer))
lStrCpy( ll_StringPointer, ls_Buffer )

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:

  • Function long LocalAlloc(long Flags, long Bytes) library "kernel32.dll"
  • Function long lstrcpy(long Destination, string Source) library "kernel32.dll"


Page 1 of 2   next page »

About Deanne M. Chance
Ms. Chance graduated in 1996 with a degree in computer science from the University of Illinois. She has been a frequent contributor to the PowerBuilder Developer's Journal and gave a key presentation at Sybase TechWave 2005 entitled "A Real-Time Physical Inventory Solution Using PocketBuilder ASA and a WiFi Connection." She has held several engineering positions, starting a career at Motorola where she focused on mobile I.P. by doing real-time embedded programming for the base radio controller group as part of the iDEN/Nextel project.

Chance wrote: Now that I think about it this really shouldn't be limited to tablet pc programming. That is somewhat misleading. You could add VoIP capabilties to any box that had an internet connection. A wireless broadband pc just happens to be one application of this.
read & respond »
PBDJ LATEST STORIES . . .
Adobe's Kevin Lynch and Microsoft's Scott Guthrie to Keynote AJAX World RIA Conference & Expo
Two of the biggest launches in Rich Internet Application history took place in 2007/2008 when Adobe launched AIR 1.0 in February '08 and Microsoft launched Silverlight (September '07). At the 6th International AJAXWorld RIA Conference & Expo in October SYS-CON Events is delighted to be
A Technology Leap for PowerBuilder Developers
Sybase has just released the latest version of its premier .NET development tool in PowerBuilder version 11.2. I am proud to say that I haven't missed a beta since November 1989 (version 0.8) and that includes PocketBuilder and InfoMaker too. I need to thank the people at Sybase for co
PowerBuilder and EAServer: Uniting the .NET and J2EE Communities
In PowerBuilder 11.2, .NET meets J2EE head-on with the capability to deploy .NET Windows Forms and Web Forms applications (as well as assemblies and Web Services) that access Enterprise JavaBeans (EJBs) in Sybase's own EAServer. As you'll see over the course of this article, integratin
HarPB Tool Review
HarPB is a specialized utility for checking PowerBuilder source objects in and out of AllFusion Harvest. It handles the special requirements of checking objects out to PowerBuilder Libraries (PBLs) and checking objects in from PBLs. These operations are non-standard to most source cont
PowerBuilder Editorial: The State of the State
Back in 2002, Sybase announced their four-phase approach toward adding .NET support to PowerBuilder. Phase 1 was the implementation of web services in PB9 and Phase 2 was the release of DataWindow.NET, which was packaged with PB 10. Phases 3 and 4 were the more significant phases. In P
PowerBuilder History - When Did Sybase Develop PB and How Did It Evolve?
I have been asked many times by various clients, students, and the IT curious about PowerBuilder: When did Sybase develop the product and how did it evolve? I keep telling this story and answering e-mails on the subject. I am now to the point where I have decided that I should have PBD
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS
SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021


SYS-CON FEATURED WHITEPAPERS

ADS BY GOOGLE
BREAKING POWERBUILDER / SYBASE NEWS
Sybase Reports Record Second Quarter Results, Driven by 15% Revenue Growth
Sybase, Inc. (NYSE:SY), the largest enterprise software and services company exclusively