Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Friday, April 8, 2011

Decoding MIME Attachments in C#.NET

I previous wrote an application that required extracting email from GMail via POP3 using C#. Now that same application has gotten a bit more complicated. I need to extract file attachments from the email. I've done Base64 MIME Encoding/Decoding a long time ago. I did not have the inclination to re-do it in C# so I went searching through the 'Net for ready-made code.

There were several open source examples, but the one that suited me best was this one from CodeProject:

http://www.codeproject.com/KB/cs/MIME_De_Encode_in_C_.aspx

For now, I'm just using the decoding part. But I foresee a need to do encoding pretty soon.

Monday, March 28, 2011

Retrieving Email from GMail using POP3 Programmatically with C#

I'm writing some new Dragonpay code to interface with UCPB's online banking system. I need to retrieve some information via POP3 protocol. POP3 is a very simple protocol using TCP stream over port 110. In fact, I've written code 15 years ago to retrieve email and read it over the phone using text-to-speech synthesis using Dialogic software. But the challenge this time is I need to get the data from Google's GMail.

Unlike regular POP3, GMail's POP3 uses SSL encryption. My limited knowledge on encryption does not extend to SSL encryption. So I did some research. The UNIX fetchmail program can retrieve GMail POP3 email with SSL encryption. But to run code after retrieving the email would require having to program with Linux and procmail. Since I mainly write in C# .NET, that was more trouble than its worth.

I eventually found my answer at Code Project -- http://www.codeproject.com/KB/IP/Pop3MailClient.aspx. Downloaded the code and it worked like a charm.

Tuesday, October 26, 2010

How to Rename Tables in Firebird

I've encountered several instances in the past wherein I needed to rename a table in Firebird/Interbase. Since there seem to be no direct SQL command to do this, I would normally go through the roundabout solution of:
  1. creating a new table with a temporary name;
  2. populating it with data via INSERT from a SELECT of the old table;
  3. dropping the old table;
  4. creating a new table with the desired name;
  5. populating it with the data from the temporary table (step #2 above)
  6. dropping the temporary table
Its a very tedious process. I recently came across a solution that modifies the system tables directly to achieve the same result in 2 commands:

UPDATE RDB$RELATIONS SET RDB$RELATION_NAME='NEWNAME' where
RDB$RELATION_NAME='OLDNAME';

UPDATE RDB$RELATION_FIELDS SET RDB$RELATION_NAME='NEWNAME' where
RDB$RELATION_NAME='OLDNAME' and RDB$SYSTEM_FLAG=0;

That's all there is to it!

Friday, September 10, 2010

Request.Redirect vs. Server.Transfer in ASP.NET

Which is "better" -- Request.Redirect or Server.Transfer? Both provide similar functionality, which is to send the viewer/browser to another webpage. But they way they achieve the task is slightly different. With Request.Redirect, the server basically goes back and tell the browser to go to a different page instead. With Server.Transfer, the server just returns a different page without notifying the browser. So the browser is not any wiser that it has already been sent to a different page. The url in its navigation bar stays the same (which is that of the original url visited).

Performance-wise, there is a difference. Because Request.Redirect is a request to the browser to go to another page, it involves an extra roundtrip. Depending on how fast or slow your Internet connection is, this extra trip can add a pause of a second or two while the browser fetch the new page. With Server.Transfer, the redirected page appears immediately in lieu of the originally requested page.

I have to admit, I'm beginning to be a bit of a fan of Server.Transfer. But most programmers don't seem to like it based on other blog posts. They say that its an old API that should not be used anymore. One of its disadvantages is that it will not allow the user/browser to bookmark a page since it does not know the actual url of the redirected page.

With .NET, passing parameters from one webpage to another using Server.Transfer requires the use of the Context objects. With Request.Redirect, the practice is to just use the more common Session object. Truth be told, I really don't understand what is the difference between those two object types. PayEasy uses a combination of both.

Tuesday, August 10, 2010

Integrating Facebook Like Button with Open Graph Protocol

I've been stumped for the past couple of days trying to figure out the Facebook Open Graph Protocol. I think I've finally figured it out today. To summarize, I have an external website based on Wordpress:


I created a Facebook Page manually using my account:


My objective was to put a Like Button (or Like Box) at my external site, which when clicked, makes the "clicker" my Facebook page's "fan".

Just like several people in the Facebook Developers Forum, I was getting that weird og:type=link error on both the Like Button and the Like Box. Sure enough, if you view the html source of the Facebook page above, you will see a meta tag for og:type=link. There seems to be no way to edit the meta tags in the Facebook page.

What I did next was to create a Like Button for my external site using the Facebook Like Button generator. As explained by another forum member, this generator seems to be intended for external websites. So I put in all the necessary meta tags on my external site (you can do a view html source of www.dragonpay.ph to see the tags I inserted in my Wordpress header.php). As expected, the "Like Button" works fine for my external website.

But wait -- this was not what I intended originally. I wanted the user to "like" my Facebook Page, not my external site. Now here's the twist that I discovered. When you ask Facebook to like your external site, it actually creates another Facebook Page for your site on-the-fly. In my case, it created the page as:


Notice that this is a completely different URL from the one I manually created above. And more interestingly, if you do a view html source of this new page, it actually has an og:type=website!

So I quickly went to the "Like Box" generator and typed in the Facebook page id of 150520031629713. And guess what -- the "Like Box" now works perfectly fine as well.

So, to summarize my findings, it seems that you cannot use the "Like Button/Box" generator and link it to a Facebook Page that you created manually. It seems that you have to let Facebook create the page for you on-the-fly by first putting the necessary open graph meta tags on your external site, then wait for Facebook to scrape it. This page that it creates on-the-fly will have the correct open graph meta tags that will work with the "Like Button/Box".

Now the only problem which I cannot answer is -- what if the original Facebook Page that you have already has a significant number of followers? How do you now switch them over to the on-the-fly version? In my case, its not a big deal since my original Facebook Page only had about 20 followers. So I'll just kindly ask them to re-click my "Like Button/Box" so that they become followers of the new page.

Tuesday, July 27, 2010

Working with Hidden Fields in ASP.NET

I need to use old school HTML hidden fields in a webpage I'm making because I need to pass it as a post parameter to an external server. I tried using the .NET server controls (ie. runat='server') but realized later that it mangles the name. So by the time the external server receives it, the names has some gibberish prefix or suffix.

Next I tried using the Visual Studio standard html hidden fields control but found out that they cannot be accessed from Code Behind. Since I need to set the hidden field values dynamically at runtime, and not at design time, that's a bit of a problem. The way I used to do it is to use the .NET Literal text control. I would put the Literal control on the page and set its value to the actual html code of "input type=hidden..." during runtime. Not a very efficient method.

After doing some more research, I found a way to dynamically insert hidden fields programmatically through the Page class:

this.Page.ClientScript.RegisterHiddenField(fieldname, fieldvalue)

That solved my problem!

Saturday, July 24, 2010

Microsoft Tags

Microsoft tag is a 2D barcode meant to be read by your mobile phone and access the corresponding information from the internet. All you need is a camera phone and the freely downloadable software from http://gettag.mobi/. Specific builds for iPhone and Android phones are available, but the more generic Java reader seem to work with most phones supporting J2ME. Microsoft Tag can read from the environments which other barcode readers cannot read such as monitors, televisions.

I tested the Tag reader on Cols' Wifi-capable Nokia phone and it was very impressive. Using 3G on my entry-level Nokia 2730 classic is another story. It takes a long time to respond after you "snap" a tag image, and it prompts too many questions before establishing the 3G connection to pull down the site content. :(

Since Microsoft Tag also uses colors to encode data, it can store more information than typical 2D barcodes. This information can be a web site address, a contact card, a text or a phone number. When you scan a tag, your phone's default browser will open a website, add a contact to your contacts, show text message or dial a number according to the tag type you scanned.

You can use the online tag manager at http://tag.microsoft.com. Its very user-friendly. It allows you to easily generate tag images in different formats (pdf, jpg, gif, png, etc.). You can modify the URL that a tag points to from the web interface anytime. You can define date ranges when that tag is considered valid for time-based applications.

Microsoft published a set of API that allows developers to create and manage the tags programmatically. This C# example is a great starting point for developers who want to get into the nitty-gritty:


Friday, April 30, 2010

Nokia Training on Qt



I attended a 3-day training at Makati Shangri-la organized by Forum Nokia. They're inviting developers to develop using the Qt Framework for the latest edition of the Series 60 phones. The Qt technology was acquired by Nokia when they bought the company Trolltech.

Qt is yet-another cross platform developer framework that uses C++. In that sense, its kinda like the .NET Framework except this one specifically works in Nokia Series 60 phones instead of Windows Mobile phone and .NET Compact Framework. It also has a lot more animation-related functions that can give Flash a run for its money. Or maybe not.

There are very few phones currently capable of supporting Qt. That is always a risk for developers to work on a platform without knowing for sure if it will become ubiquitous or it will end up in the technology graveyard.

I have to admit that the Qt framework is a helluva lot simpler to use than the old way of writing Series 60 apps using C++ and the Series 60 SDK. But I still haven't thought of a compelling reason to start writing Qt programs.

Monday, March 1, 2010

Simulating Keyboard Input with C# Part 2

A week ago, I was discussing how to simulate keyboard input into another application with C#. While the method of using GetProcessByName() works fine, it seems to be dependent on the Windows performance counters being enabled. I'm not sure if its just my Comodo Firewall which is blocking the writing to the restricted Windows area or its something else, but my old Visual Studio 2003 application could not successfully use the GetProcessByName() method that I used with my Visual Studio 2005 test. The FindWindow API call seems to be the more universal approach of getting the handle of another running Windows application.

To access, FindWindow or FindWindowByCaption, use the following pinvoke declarations:

[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
static extern IntPtr FindWindowByCaption(IntPtr ZeroOnly, string lpWindowName);

Use FindWindow() if you are searching using the registered "Class" name. Otherwise, if you want to use the text that appears on the Windows title bar, use the FindWindowByCaption() API call.

IntPtr hWnd;
if (externalAppType == "CLASS")
hWnd = FindWindow(externalAppName, null);
else
hWnd = FindWindowByCaption(IntPtr.Zero, externalAppName);
if (hWnd != IntPtr.Zero)
{
if (SetForegroundWindow(hWnd))
{
System.Threading.Thread.Sleep(50);
System.Windows.Forms.SendKeys.SendWait(id + "{ENTER}");
}
}

Monday, February 22, 2010

Simulating Keyboard Input with C#

I visited a potential client who is using a barcode reader-based timekeeping system. Well, actually, the barcode reader is just configured as a keyboard wedge. So from the application's point of view, it just looks like a the user is typing his ID number on the keyboard. This prospect is interested in shifting into a fingerprint-based biometric timekeeping system. But because of their complex business rules, we looked at ways to implement the biometric identification as an adjunct to the existing system.

So the challenge is -- how do I capture a fingerprint; determine its associated ID; then simulate a keyboard input to their existing keyboard-based 3rd application so that no changes need to be made on their end. The same business rules would apply. Since their program is keyboard-based instead of serial or USB, that greatly simplified matters. I recall reading of a Windows API to send characters to the 'keyboard' device to make it appear as if somebody inputed something on the keyboard. But the extra challenge here is to be able to send those virtual keypresses into another running application.

A little Google search for examples in C# yielded some answers. The SendKeys class in .NET Framework already encapsulated the Windows API calls to do this. I just need to first invoke SetForegroundWindow() to transfer control to the application that I want to send the keys to, then SendKeys does the rest. There is no existing encapsulation of the SetForegroundWindow() API call in .NET so I had to use the platform invoke (pinvoke) method. This is easily done with the ff. declaration:

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);

As can be seen from the declaration, SetForegroundWindow() requires a native Window handle as a parameter. One way of getting a window handle is by enumerating the processes running in a system. The process object's MainWindowHandle property is what we need to pass to the API.

Process[] processes = Process.GetProcessesByName("notepad");
foreach (Process p in processes)
{
IntPtr pFoundWindow = p.MainWindowHandle;
SetForegroundWindow(pFoundWindow);

System.Threading.Thread.Sleep(50);
System.Windows.Forms.SendKeys.SendWait("Hello world");
System.Windows.Forms.SendKeys.SendWait("{ENTER}");
}

The above example assumes there's a Notepad running on the system. This program sends the text "Hello world" to the notepad's window. Based on my tests, the Sleep call is important as it takes a split second for SetForegroundWindow() to switch windows. Without the needed pause, the first few characters of the keys to send are missed.

Wednesday, February 3, 2010

Getting Foreign Exchange Currency with C#

Since our online payment service PayEasy works with 24 countries for direct bank debit, we have to perform currency conversion as necessary. For the longest time, I have been using the free currency converter Web Service at webservicex.com -- com.webservicex.www.CurrencyConvertor().

But lately, I don't find it very reliable. I would often get time-outs or errors. Also, I'm not really sure as to where it gets its exchange rates. For manual currency conversion, I prefer to use the service of XE (http://www.xe.com/). However, XE does not provide an API for getting rates. So I decided to just implement my own API by retrieving the output of XE.com and parsing it.

Luckily, its fairly simple as they display the rate right at the page's title bar. So its a simple matter of crafting the necessary HTTP GET request given the source and destination currency. Then read the page header of the response and extract the rate from the title.

Below is a snippet of my C# code:

string xeString = String.Format("http://www.xe.com/ucc/convert.cgi?Amount=1&From={0}&To={1}", srcCurrency, dstCurrency);

System.Net.WebRequest wreq = System.Net.WebRequest.Create(new Uri(xeString));
System.Net.WebResponse wresp = wreq.GetResponse();
Stream respstr = wresp.GetResponseStream();


int read = respstr.Read(buf, 0, BUFFER_SIZE);
result = Encoding.ASCII.GetString(buf, 0, read);

At this point, the string result already contains the title which can look something like
XE.com: USD to EUR rate: 1.00 USD = 0.716372 EUR. As can be clearly seen, its a simple matter of parsing the title in order to get the rate.

Wednesday, September 23, 2009

Programming with Windows Media Player and C#

I'm working on a prospective project that requires me to play mp3 files on our NetMachine kiosks. Under the old Windows system, one can play WAV files by calling some internal Windows functions. I've never tried playing mp3 or wma media files from an application so I did some research. While there are 3rd party libraries available, the best option seems to be to use the interfaces exposed by Windows Media Player (WMP). Since practically all Windows PC's come equipped with some version of WMP, it is fairly safe to assume that the components can be found in all these PC's.

Adding WMP to a C# application is very simpler. Just add a reference to the file wmp.dll in your Visual Studio project. Then from within your code, just create an instance; point to the source media file; and call play():

WMPLib.WindowsMediaPlayer player = new WMPLib.WindowsMediaPlayer();
player.URL = @"c:\My Music\somesong.wma";
player.controls.play();

You can also track state changes (eg. from playing to stopped) and respond appropriately using the standard event-handling model of .NET.

player.PlayStateChange += new WMPLib._WMPOCXEvents_PlayStateChangeEventHandler(player_PlayStateChange);

You can also access the playlists defined in WMP programmatically, and extract information about the media file (ex. the artist, song title, album title, etc.) through the IWMPMedia interface:

WMPLib.IWMPMedia objMedia = player.currentMedia;
listBox1.Items.Add(String.Format("[{0}] {1} by {2}",
objMedia.getItemInfo("Album"),
objMedia.getItemInfo("Title"),
objMedia.getItemInfo("Artist")));

There is a downloadable Windows Media Player SDK 10 at Microsoft. I'm not sure what more it adds to the components that are already built-in to Windows. I did not bother installing it anymore. I guess its just sample programs.

Tuesday, September 22, 2009

Programming with Multiple Monitors in Windows using C#

I have a couple of prospect projects that require the application to send 2 different outputs to 2 different monitors. While I have been curious for some time about exactly how do you install more than 1 video card/monitor onto a Windows box and extend your desktop, I've never really been pushed to find out. But because of this prospect, I assigned my tech guys to do some R&D using our notebooks.

It seems that all Notebooks have 2 x video cards built-in -- one going to the LCD display, and the other going to the external VGA port. I have always assumed that it was just 1 video card and that the VGA port is just like an "extension" of the LCD. But as it turned out, Windows treats them as 2 different video cards and you have to option of whether their output to be the same, or you want it to be in "extended desktop mode".

Detecting multiple screens under C# is very trivial. The only thing that makes it a bit tedious to work with is the fact that the Display names are null-terminated (C-style). Since C# does not work natively with null-terminated strings, you have to do a little bit of conversion to C#-style strings. The example below shows how to get device info and open a modeless window which will reside on the extended desktop.

Setting the bounds of the new window to that of the extended desktop and setting the WindowState to Maximized will cause the modeless window will eat up the entire extended desktop. Of course, this simplistic demo assumes there are only at most 2 monitors. In reality, according to other postings, Windows XP and Vista officially can support up to ten (10) video cards/monitors.


allScreens = Screen.AllScreens;
foreach (Screen screen in allScreens)
{
string deviceName;

int length = screen.DeviceName.IndexOf("\0");
if (length == -1)
deviceName = screen.DeviceName;
else
deviceName = screen.DeviceName.Substring(0, length);
}

ExtendedForm extForm = new ExtendedForm();
extForm.Show();



Then at the constructor of the Extended Window Form:


private void ExtendedForm_Load(object sender, EventArgs e)
{
Screen screen;

Screen[] allScreens = Screen.AllScreens;
if (allScreens.Length == 1)
screen = allScreens[0];
else
screen = allScreens[1];

this.Bounds = screen.Bounds;
this.WindowState = FormWindowState.Maximized;
}


Thursday, August 27, 2009

Mifare Cards Now Supported by NetSecure

Although I've always believed in the philosophy behind Object Oriented Programming (OOP), I have to admit that in most cases, I still program in traditional, structured, procedural style. This even though languages like C# or Java treats everything as classes, even the main program itself.

The most OOP-heavy program I've ever written is our *ahem* best-selling NetSecure biometric time and attendance system. Since NetSecure aims to support as many devices as possible for identification and verification purposes, early on, I designed it to use OOP heavily. All devices I support (fingerprint scanners, RFID readers, magstripe readers, pinpads, etc.) are derived and implemented from two other layers of abstract classes. At the bottom is a generic InputDevice abstract class. Then a generic ProximityReader abstract class is derived from it. Then finally, an RFID-specific implementation like the GigaTMS' GP20/30 RFID reader is implemented.

Recently, a big client requested for support of Philips Mifare cards. I've been twiddling with the ACR120 Mifare reader for some time. I've written small programs to test its capabilities, but have never actually written a full-blown program to make use of it. I was estimating it could take me a couple of weeks to write all the code to integrate it to NetSecure.

When I finally got down to coding and followed my object models, I realized that the ACR120 reader is just like a GPxx RFID reader. So I created an ACR120MifareReader class that is derived from ProximityReader; implemented the abstract interfaces to allow the main program to connect/disconnect to it and retrieve inputs; and voila -- I was done in about an hour! Turns out that very little changes were needed on the main NetSecure code itself as most access to devices go through the class abstraction interfaces.

Friday, July 17, 2009

Visual C++ 'per-appdomain symbol error' and Compiler Warning C4394

I've been trying to debug my telephony test application the past week to no avail. I asked Aculab for technical support and their engineer asked me to enable the built-in trace capability of their library. When I enabled it, I got all sorts of Compiler Warning C4394:

per-appdomain symbol should not be marked with __declspec(dllimport)
Visual Studio also refuse to link the application citing those cryptic unresolvable externals on the trace variable and function. Doing a Google search on the strange error revealed that there are other people who have experienced the same problem. The error does not seem to appear if the application is a console app (such as the demo SimpleCall that came with Aculab's SDK). But the moment you switch to a graphical CLI/.NET environment, it appears.

According to MSDN, the C4394 is related to variables or functions written and compiled using native C/C++. When they are linked to a program compiled in Microsoft's Intermediate Language (MSIL) format running in a .NET managed environment (CLI), the incompatibility in permission access level appears.

Somone suggested in the forum from the other guy who reported the same problem to switch from a "pure" CLR environment to a normal one. This can be achieved by changing the compiler flag from /clr:pure to just /clr. From the Visual Studio IDE, one goes to Project >> Properties >> Configuration Properties and change the Common Language Runtime support dropdown value to regular /clr instead of the default "Pure".

And what do you know? It worked! The compiler and linker errors disappeared and I was able to generate by trace logs. So its now back to trying and figure out what is wrong with my demo program. :(

Wednesday, July 8, 2009

Using app.config with Visual C++/CLI

Still on my C++ project with Aculab, I tried putting my application parameters onto a .config XML file just like I normally would with my C# programs. The steps seemed obvious at first -- I added a config file using the templates, then I added a reference to the System.Configuration assembly.


But from inside my code, calling ConfigurationManager::AppSettings does not seem to resolve to anything. I checked the output folder and did not see any application.exe.config that one normally expects from C# projects.

I did a little bit of research and found this app.config article for C++/CLI in CodeProject. It seems that the key is in the project property's post-build event. Specifically, you have to run the external command:
copy app.config "$(TargetPath).config"

This properly copies the config file to the object code output location where it can be read by the application.

The next hurdle is converting the managed System::String^ class, that is returned by the System::Configuration methods, to the old c-style null-terminated string. This one is achieved by using the System::Runtime::Interopservices::Marshal methods. The shortest way of writing this expression that I've seen is this one from MSDN.

Saturday, June 20, 2009

Globe + Google Developer Workshop @ UP Technopark

I attended the Globe Labs + Google developer event at the UP Ayala Technopark along Commonwealth Avenue. While I have passed by the Technopark several times, this was my first time to actually enter the compound. The place is very clean with low-lying buildings and wide open spaces. It reminded me of Silicon Valley environment (except for the heat).



The event was supposed to start at 1pm. I got there at about that time figuring that most people will be late anyway, as is typical for these events. But surprisingly, the place was packed with geeks (and I mean that in an endearing sort of way) by the time I got there. I guess geeks are more prompt with time unlike your average Filipino.

Google showed off their API's for developers to "mashup". The Globe Labs guys demoed their Location Based Service (LBS) API, and showed how it can be used to work in conjunction with the Google API to do really creative things. The Google guy also showed some really interesting developments going on at Mozilla/Firefox with respect to HTML5. New HTML elements like canvas and video allows for really interesting possibilities that should give Flash and Silverlight a run for its money in the very near future.

Amidst all the gee-whiz-bang show-and-tell, what really caught my attention was the Google Visualization API. The map that appears in Google Analytics showing where your visitors are coming from in a graphical manner, can apparently be easily used in other programs. What immediately popped to my mind is integrating it with PayEasy Admin to allow merchants to see where their payers are coming from in a visual manner. This led to my implementation of the API.

For an even simpler way of mashing up contents without any programming involved, Google Web Elements comes to the rescue. Copying-and-pasting HTML is all it takes to embed a calendar, presentation, spreadsheet, map or YouTube video to your site. Now I just have to figure out what the longitude/latitude valus of The Peak so that I can provide a map to our office from our website!

Friday, June 12, 2009

Wrestling with C++/CLI

I'm looking at a possible computer telephony project that might make use of Aculab's products. I used the Aculab PCI card back in 2002 to do SS7/C7 switching with the telcos when I was still in that line of business. Ah, those were the days when I lived and breathed Dialogic code.

I remember the Aculab card as a very powerful card and quite affordable for something that can do SS7. Dialogic's equivalent product (the former DataKinetics) cost considerably more especially if you factor in the cost of the software. In the case of Aculab, the software protocol stacks are free. You just buy the board. And with Linux support plus great technical support, it was a hands-down winner.

I've been studying the trial version of Prosody S, their host-based media processing (HMP) platform. The API's only support C/C++ for multi-platform portability. I was hoping they would have C# libraries but unfortunately, they did not. Their pre-sales tech guy gave me a sample in C#, but it makes direct socket calls, as opposed to, using the API function calls. So it looked really messy.

So I figured I might as well install Visual Studio's C++ and see if I can shake off my C++ cobwebs. I haven't written in C++ for probably 5 to 6 years already. And when I did write in C++, I used Borland C++Builder for Windows and the GNU C++ compiler for Linux. I never actually used Microsoft's Visual C++. I never bothered to learn the Microsoft Foundation Classes (MFC). So I figured I'm going to have a bit of an uphill climb here.

After installing VS2005's C++ support, I made it create a .NET windows app using its templates. When I saw the code, my first reaction was -- What The F***?! It looked totally alien and unlike the C++ I knew. There were new operators (the caret ^) which I'm pretty sure is not part of standard C++.

I tried copying-and-pasting some code from the Aculab examples, and the compiler gave me all sorts of error messages about converting unmanaged code to managed. The uphill climb is starting to look like an up-mountain climb. As usual, I went to Google and did some query on C++/CLI (Common Language Infrastructure). The CLI is Microsoft .NET's common managed environment for its new generation of languages. Using C# and VB.NET with CLI is really trivial. But using it with an "old", unmanaged language like C++ involves a lot of changes.

Here are some quick tutorials I found on getting up-to-date on C++/CLI:
Just converting between the old, null-terminated string (char *) in C/C++ to the managed System.String (or System::String in C++/CLI format) version involves several steps. But I guess that is really the way to go. I mean, doing Windows programming with MFC or the native Windows API calls is a worse option.

Friday, June 5, 2009

Web Sites Projects under Visual Studio 2005

I've been looking at some sample code lately that requires Visual C++ compilation. Since I have been mainly doing C# programming the past several years, I never bothered to install the C++ option of Visual Studio (2003 and 2005). But now that I do need it, I popped in my MSDN DVD and tried to add C++. It gave me some strange error and refused to install it. So I had no choice but to uninstall Visual Studio 2005 and reinstall it -- this time with C# and C++.

The process seem to have worked as I can now view the C++ sample codes. But strangely, when I try opening some of my C# projects, Visual Studio 2005 would complain about unsupported project files. This is particularly true for my really old web/web service projects which I migrated from VS 2003 to 2005. VS2005 just doesn't seem to like their .csproj files.

After some tinkering around, I noticed that VS2005 web site/service projects do not seem to need a .csproj files. In fact, deleting the .csproj files seem to fix the problem. The project could then be added/loaded onto a VS Solution without any hassle.

On another note, I also recently installed Windows XP Service Pack 3. Although SP3 has been around for some time, I haven't really bothered to install it. Now that its installed in my system, I'm experiencing weird problems with my Virtual PC. The problem seem to specifically happen when I do large file transfers between my Virtual PC session and my host PC. It just reboots my entire machine without any warning. Grrr... the lesson is -- don't load new Microsoft service packs unless you are specifically experiencing problems that require it.

Wednesday, May 13, 2009

Globe Labs Training

Globelabs, the innovation arm of Globe Telecom, conducted a developer training tonight at Powertips in Podium.  Globe has been encouraging developers to take advantage of its test platform to come up with interesting apps.  They have previously opened up API's for SMS, MMS and LBS (Location-based Services).  Tonight, they announced the availability of the Voice API.

The SMS, MMS and LBS API's are very straightforward to implement.  They can be accessed using standard HTTP REST (aka. name-value pair) format.  For Microsoft Visual Studio-based developers, a SOAP interface is provided complete with WSDL for easy referencing.  Developers are given a small quota of SMS/MMS to send/receive everyday for testing purposes.  Responses are sent back in industry-standard XML.

The Voice API, however, is quite a different story.  In fact, I would dare say its not much of an API.  The only API-ish thing about it is the "getConsent()" part, which is similar to LBS wherein the user has to provide consent somehow that he will use it.  I'm not really clear as to why this is necessary.

The rest of the "voice API" is really just standard Session Initiation Protocol (SIP).  You are basically on your own to implement it (or to use open source applications like Asterisk to implement it).  One concern brought up during the training is the choice of G.729 as the audio codec.  G.729 is a proprietary codec that requires commercial licensing/royalty for use unlike other codecs like G.711.  It has a low bandwidth requirement (8kbps, by default) though, which is why telcos favor it.

I guess I'll be doing some tinkering with this in the coming weeks.