Sunday, March 1, 2009

Retrieving information from an external application: Part 1

Good evening,

Have you ever been in a situation where your application had to communicate with a 3rd party application that you obviously don't have the source code for?  In my situation, I have to be able to retrieve information out of the client's internal application that they themselves didn't write.  We can't ask them to modify their application to give us the information we need to be able to provide them with the needed information from our .NET application.  What to do then?  This is what the IT world calls "cross process" or "remote process" communications.  What are our options?  After some research and common consensus  among my co-workers, we decided to use Desaware's SpyWorks for the solution.

In a nutshell, SpyWorks is a set of libraries that work in one of the basic level of the operating system and with some API calls to the correct methods, we are able to retrieve said information from 3rd party applications.

What is my objective in this situation?  To retrieve information from multiple types of controls in the client's application.  These components are single-line text boxes, multi-line text boxes, rich text boxes, labels, combo boxes, list views, list boxes and tree views to start with.  Overall, I want to be able to retrieve the information, and in the case of multiple choices, the user selected item in the 3rd party application.

To be able to test my code, we'll have to create a test application with all said controls on it.  A simple form with 1 control of each type will suffice.  One more control will be added to the bottom of the form, and that will be a label that will indicate the selected control's "handle".  More on this later.  Here's what the form will look like:


As you can see, I have all the different kinds of controls that I'm looking to retrieve information from.  They are all populated with data and represent a good test form for our purpose.  The only code in this form is for the Click event of each control.  All these event methods do are to put the selected control's handle in the label at the bottom of the dummy app's form.  The following image represents the code behind the DummyApp form:


Now let's look at the application that will be retrieving the information.  It will need a way to indicate which control we want to retrieve the information from, a button to start the retrieval and a textbox of some kind to display the information that was retrieved.  Here's what this form looks like:


As you can see, it's a very simple form with various buttons.  I'll go into details further down, but simple to say that each button allows you to capture information out of a specific type of control, 7 control types to be exact.  The sample applications are written in C# for .NET 2.0 using Visual Studio 2005 Professional.  It is good to know that each control has it's own way of storing it's information in memory, hence the different buttons.  It would have been too easy if Microsoft had made it that all controls' information could be retrieved the same way.

How do you find out which API method you need to call with which parameters to obtain the information you want?  Well, to be completely honest, I don't know if there's a good place to find all the needed information.  I did my research using Google's search engine and with lots of tries, time and patience, I found the necessary information.  Not all of it was readily available, but with some persistence and some trial and error, I was able to make each control retrieval work.  Make no mistake, I'm not a master of the Windows APIs in any way, shape or form, but after this project, I do know that much more about it then when I started.

Each API method requires a parameter called "handle" that points to the control that you're trying to retrieve information from.  That's what that label at the bottom of the dummy application is for.  When you click on a control, the label will display that selected control's handle for you to use in your calling application.  In the real world, 3rd party applications will not provide you this information and you'll have to use applications like Spy++ (distributed with Visual Studio) or write one yourself to find this information out.  The details on how to write your own application to find 3rd party control handles will be for another time and another article.  For now, all you need to know is that the dummy application provides you this information in the bottom label and you need to enter this number into the testing application's top text box and then click on the appropriate button to be able to retrieve the information from that control.

In part 2 of this article, we'll dig into the testing application where all the code and API calls to retrieve the selected control's information is located.

Until next time,

Sebastien Limoges

Wednesday, February 18, 2009

Luck of the draw... or is it?

Have you ever wondered what those drawing/raffle winners do to win, or how they win multiple times?  The thought has crossed my mind more than once, and I suspected that some "trick" was involved somehow.  Let's see if I can show you what I mean by an real life example: me.

Today I was at work in the middle of doing research on a coding error I was receiving in my code when I get a call from my wife.  She tells me "You did it again!".  At first, I'm kickly trying to figure out what I did this morning and why was I in trouble for it.  She then proceeded to tell me that I didn't do anything wrong, but rather that I had won another prize from the PGA Tour Partners Club.  I won a complete set of King Cobra S9 irons in the January 2009 drawing.  To put things in perspective, I won a King Cobra LD Speed Pro S driver back in December 2007 by also entering in a PGA Tour Partners Club drawing.  About 2 years later, I win a complete set of irons from the same manufacturer and from the same company doing the drawing.  What "trick" did I use to win?  Who did I have to pay to make the odds better for me?  The answer to those 2 question: none.

Let me explain the details of the PGA Tour Partners club drawings.  You go to their website and log in to your account.  You then proceed to click ont he Contests tab and pick which contest you want to participate in.  The only restriction the club has is that you can only enter in the drawings once a day.  So my "trick" if you want is that I went to the site daily to enter in the drawings.  Most drawings are for a month, but some are for 2 months.  If you go there every day, that's at least 30 entries (except for February) for each drawing.  Now I know I'm not the only one in the club and there are tens of thousands of people, if not more, that do something similar to this (at least they will after they read this).

Putting all this together made me realize that there is no "trick" or "black magic" involved, but rather perseverance and dedication to the "cause", which in this case, is a drawing.  If you want to participate in a drawing, find out what the rules are and if you're allowed to enter multiple times.  It is very important to find out if purchases are necessary to enter and/or if there is a cost associated with entering the drawing.  In my case, you have to be a member of the PGA Tour Partner Club to participate in it and you have to decidate the time to do the entries each and every day.

Hope this shed some light on the mysteries of how people win drawings/raffles.

Until next time,

Sebastien Limoges

Friday, January 30, 2009

LogMeIn to the rescue!

Have you ever been at work and realized you needed something from your home computer?  Have you tried calling to someone at home to send you what ever file you needed by email?  Worst yet, have you had to drive home due to the fact you wanted a file from your home computer?

Well, that very situation happens to me on a somewhat regular basis.  No, I'm not an air head, but I do work from home and the office, so sometimes, the latest version of my work is at home.  This has bugged me to no end.  I don't want to setup an FTP server at home just so I can access those files since then it becomes a management nightmare.  I want to be able to remotely control my machine from wherever I am (office, vacation, remote site) without having to install a bulky app.

I did some research and found LogMeIn.  Now this is a Remote Desktop software that works through the web browser.  It's encrypted, password protected and fast!  It's so good, that it's the unofficial remote desktop software that my co-worker use to work from home!  I use it to have access to both my computers at home and to troubleshoot computers of friends and family.  The great thing is there's an version that is free!  You read right, free!  If you can live without remote printing, sound & file moving, then you can use the LogMeIn Free edition.  If not, they have LogMeIn Pro for a small monthly fee.  For what I use it for, I use the free edition.  Simply go to http://www.logmein.com and create yourself an account, you'll be glad you did!

Wednesday, January 28, 2009

Visual Studio Google Gadget - Revisited

Since my last post on Google Gadgets, I have used my Visual Studio Recent Projects gadget on a daily basis.  It quickly occurred to me that there are enhancements to this gadget that would be useful immediately and not just to me, but to the general public.

Here's a quick rundown of the enhancements that I thought would greatly benefit my Google gadget:
  1. Change the blue underline (anchor link) to something more pleasant
  2. Highlight the item that you're over in a different color to see which one you're selecting
  3. Remove file extensions to the items listed
  4. Ability to see more than just the first 6 projects/solutions
The first 2 items is pretty self explanatory: it's ugly the way it is.  It's functional, but it detracts the eye and is esthetically unpleasant.  So I went in the code and changed it to be an off white color with no underline.  I then added code to change that color to a soft yellow when the mouse hovers over the item.

The 3rd item is simple to fix but then brings up a new issue: how do you tell the difference between a solution (.sln) and a C# project (.csproj) in the list?  My thoughts on this at the moment are:
  • add a tooltip to the items that would add the full path & filename and, to add a little bit more information, when was this item last opened.
  • add an icon in front of each item that would differentiate each item based on their extension.
I changed the code to remove all extensions, and added an icon based on the first 3 letters of the extension.
The 4th item is easy in concept: have pages of x items show up and a way to move between pages.  The implementation wasn't as easy.  It wasn't complex, but wasn't complying very well either.  Basically, I figured out how many items I wanted to display on a page (which is 7), then I used math and constants to figure out on which page the user is on to display the proper items out of all possible ones.  I gave the user 2 arrow buttons to allow the user to navigate forward and backwards in the pages.  The list is not sorted, just the same order that it is in the MRU registry.  I guess that could be a future enhancement.

The end result looks something like this:


As you can see, it looks much better than the 1st iteration of the gadget.  With all this, what's left to add you ask?  Where if you remember, I mention that a tooltip would be useful.  A tooltip with the full path of the item would be useful in cases where there multiple versions of the same project  How do you tell them apart?
 
If you have any suggestions as to what other enhancements this gadget could use, please leave a comment and I'll definitely consider it.

As always, you can download the most recent version of the gadget (Visual Studio Recent Projects-Sebastien Limoges.gg) and you can read up on what people have to say about it by going to it's Google page.

Until next time,

Sebastien Limoges

Monday, January 26, 2009

Holidays, sickness and work

Hello all and happy 2009!

I'm sorry there's been such a gap between this post and last post. With the holidays, work and me being sick, there hasn't been much time for me to post. I'm hoping to get back on track and keep you posted on my progress (or lack thereof) on my GPS Golf project.

In the spirit of this project, I went out and tried my hand at a round of golf this past Saturday and have played what is probably my worst round EVER since I've been married and moved down to Florida. I posted a 118, with at least 3 holes of 10 strokes! The other big change was that I also posted many 3 putts, which is a rarity for me usually. What is the cause of this abomination? My tempo was off, I could barely breath (breathing through my mouth, except when swinging, which raised my blood pressure I'm sure) and the fact that I'm following a friend's suggestion and changed golf balls from Nike Distance to Bridgestone e6+. Golf balls don't mess your game you say? I disagree... especially if they add about 20 yards to your distance and have enough spin to stop (or backspin) once they hit the green. Try to figure out during all this disarray which club to hit to reach the center of the green which is 156 yards away... oh and don't forget that your normal 7 iron won't do now that it's 170 yards and not 150 yards! Anywho, I have work to do. I have to work on my tempo, keep strenghtening my fingers and get better health wise. The only worthy shots to note are a 60 yards chip in the hole and a 42 foot down side hill put to save par.

With all that said, you have a good week!

Sebastien

Thursday, December 18, 2008

Visual Studio Google Gadget

I was curious as to how Google Gadgets worked, and for that matter, how they were built. I set out to Google's site and looked up Google Gadget. Found the API, downloaded the SDK and I was off to a good start. My project: list recent Visual Studio projects. One step further than that, I want to be able to select which Visual Studio version I wanted to list the projects for.

After a bit of research of how to access the registry through javascript, I was off to a good start. I created the basic form, which was basically just a shell, no real content. On the load event, it would call a method that would 1) find out which version of Visual Studio to look at 2) look under the proper Visual Studio folder and see what recent projects are in the MRU. For each project found, it parses the string path and keeps the solution name and sticks it in a label on the form. If no projects are found, it creates a label that says "No Projects".

I then proceeded to create the Options page, which basically is just 3 mutually exclusive checkboxes for the 3 Visual Studio versions in question (2003, 2005 & 2008). Based on what is selected here, this will affect what is displayed on the main form.

Finally, I worked on the information displayed in the About page. I created the package (*.gg file) and tested it out thoroughly. It works like a charm!

If you're interested, here is the code (VisualStudioProjects.zip) and the gadget (Visual Studio Recent Projects-Sebastien Limoges.gg).

Tuesday, December 9, 2008

Google Maps vs Virtual Earth

I started looking at the details of Google Maps (GM) and noticed that they ignore everything after the 6th decimal. Normally, I'd say that's good enough, but in the case of GPS locations, that is very limiting. I then looked at Virtual Earth (VE) and noticed they didn't have that limitation. The other advantage of VE vs GM is that there's a higher threshold for requests per day and no need to register to receive a special key.

So I set out to test the flexibility of this Virtual Earth and quickly notice that it's using HTML and JavaScript inside a browser. This might be troublesome later when I try to stick this on the Window Mobile 6 (WM6) platform, but I'll deal with that later. For now, I just want to see if I can do what I want in a quick prototype fashion.

I start looking at the Virtual Earth SDK (http://msdn.microsoft.com/en-us/library/aa905677.aspx) and looking at the live demo (http://dev.live.com/virtualearth/sdk/) I see all I could possibly want for this project: type of map (Road, Satellite, hybrid), I can add pushpins (which are Shapes in VE) and I can grab coordinates by responding to mouse events.

After a few hours of testing and messing around with the different possibilities and permutations, I came up with a finished product that quickly demos the ability of VE for this project. You can get the code for this example at the bottom of this entry.

For the purpose of this prototype, I went back again to my good old blue hole #1 at NAS Jacksonville. I first set the "center" of the hole to get the appropriate map. I then set tentative 100, 150 & 200 yds markers and I set another one to simulate where I'd be on the tee box. I add event handlers for the mouse clicks. I set different functionality for both left click and right click. Left Click gets the coordinates of where I clicked on the map both in pixels & in latitude and longitude. It also tells me the distance (yds & ft) from where I clicked to where I'm currently at. Right Click sets my new current location, which would be handled by the GPS data normally. I also added two buttons, a plus and a minus to assist with zooming in and out (if you don't have a scroll button on your mouse). You can see below a screen shot of what it looks like in IE6.

All and all, I'm very happy with this prototype. The next step will be to figure out how to stick this inside the WM6 environment.

Until next time,

Sebastien Limoges