Archive for the ‘code’ Category

Making the interface that works best for you

Thursday, January 18th, 2007

I’ve mentioned several times before how easy Visual Studio makes it to knock up mobile applications. This is one of my favourite aspects of Windows Mobile. Why put up with an interface that doesn’t work for you? If you’ve got a spare hour, make a customized interface that gets your phone to work in way that suits you better. You can create a new interface (a ‘form’) without knowing any code – just drag-and-drop to put buttons, pictures and text where you want them. Then fill in the empty methods to get the buttons to do stuff – most of the core applications expose an API that let you drive them from your own forms.

In this post, I’ll go through an example – what I didn’t like about the WM interface, why it didn’t work well for me, and how I hacked together a new interface this evening.

(more…)

Calling the Windows Mobile emulator

Wednesday, January 10th, 2007

This is apparently an old tip, but was new to me so thought it was worth posting:

…you can make phone calls or send SMS messaages to yourself in the [Windows Mobile SDK] emulator. The phone number for the emulator is “+14250010001”. This is really handy for testing SMS interception or how your apps responds to an incoming phone call, etc. Just send an SMS to +14250010001…

…It’s also a great way to freak your buddy out who’s working on the emulator and doesn’t know about this feature.

Write a little app that will place a call to the emulator with a time delay before it places the call, deploy it when he’s not looking and start it. Wait your prescribed timeout and watch as he tentatively answers the call from his emulator 🙂

from Windows Mobile Team Blog

Cool! 🙂

Strings in C can span multiple lines

Tuesday, December 19th, 2006

I came across a multi-line string while doing an inspection on a colleagues C code. I’ve never seen this sort of thing before, and didn’t know it was possible.

Something like this:


    char* welcomeMessage = "Hello "
                           "Dale. "
                           "How are you?";

    printf("%s", welcomeMessage);

will happily print out “Hello Dale. How are you?”.

It seems that you can define a string literal in C across multiple lines, without any need for a concatenation character (like ‘+’ in Java and C#).

I like that, even though I’ve been writing C for years now, I still occasionally come across little bits and pieces in the language that are new to me. And doing code inspections and reviews of other people’s code are a good way to share this sort of stuff and learn from each other.

Supporting different languages

Sunday, December 3rd, 2006

I got an email on Friday from a German guy called Bernard. He uses my wiki note-taking app that I wrote to play with the Windows Mobile SDK (that in itself was a surprise!).

He asked if I’d add support for accented characters to it, as he (unsurprisingly, being German!) wanted to use German characters in his notes. That was an easy enough fix – just add a lookup table to the wiki markup parser which replaces characters with their HTML code equivalent.

Hurrah – I could feel suitably smug for making it a little less English-centric.

A guy called Alex brought me back down to earth on Saturday morning with an email pointing out that when he uses my wiki note-taking app (wow – how many people are using this??), it displays the wrong Chinese characters in ‘View’ mode to the ones he enters in ‘Edit’ mode. Chinese? Eeek… this isn’t something I knew about.

(more…)

Google Maps mash-ups are easy

Wednesday, November 29th, 2006

A colleague from dare2, a youth development charity based in Woking, asked where the nearest IBM location to him was. I didn’t know.

The IBM UK website gives a list of UK locations. But there are two small problems. One – my geography is so bad that I don’t know where Woking actually is. Two – my geography is so bad that I don’t know where each of the IBM locations on the IBM list are. Okay, it’s really one reason, but it’s embarrassing enough that it’s worth mentioning twice 🙂

So, I thought this would be a good enough excuse to try creating my first Google Maps mash-up.

(more…)

Windows Command Line has got smarter

Friday, November 24th, 2006

Most die-hard command-line fans tend to agree that the Windows Command Prompt isn’t great. When you consider how old it is, it isn’t all that powerful. This isn’t the end of the world, as there is always cygwin.

But now Microsoft have released their new command prompt PowerShell. I tried downloading it this evening, and so far, I really like it.

(more…)

I can be a C-numptie

Wednesday, November 22nd, 2006

This might not be earth-shatteringly new to those who have seen my code before, but I was a little surprised. 🙂

A C program that I wrote a little while ago (and has previously worked fine on Windows, Linux, Solaris and HP) failed horribly on AIX. A little digging showed that I had written:

char* thisIsSupposedToBeAString[256];

I guess that at the time I wrote it (presumably early in the morning, and caffeine-fuelled) I had a string (char thisIsSupposedToBeAString[256];) and wanted a pointer to it, so went back and stuck a * on it without thinking.

(more…)

Using Scheduled Tasks and batch files to do automatic backups

Friday, November 17th, 2006

As I’ve started storing all of my project work and GTD notes in my Wiki program, I thought it might be a good idea to take regular backups of the text files it uses for data. And being a geek, I thought I’d automate it. 🙂

@ECHO OFF
REM this makes the batch file less noisy - dont 
REM  output commands to screen

REM limit scope for environment variables created here REM to within this batch file only SETLOCAL
REM make a note of where the current directory is REM so we can go back there afterwards REM (useful when running this batch file manually) set DIR_TO_RESTORE=%CD%
REM run the 'date /t' command REM this outputs in the format: REM 19/11/2006 REM (probably different for people with non-UK regional REM settings)
REM Using for to look at bits of date individually... REM FOR /F ["options"] %variable IN ('command1') DO command REM options - REM tokens - identify which bits of the date output I want REM (3 tokens - day month year), REM delimiters - how they are separated ('/') REM (users with non-UK regional settings might REM need to change this - e.g. for '-') REM command - REM 1) date /t - show date without prompting to change it REM 2) set - set environment variables to store each token FOR /f "tokens=1-3 delims=/ " %%G IN ('date /t') DO ( REM set environment variables to store individual date values REM (assumes date/month/year - users with non-UK regional REM settings might want to switch date and month) set dd=%%G set mm=%%H set yy=%%I)
REM this gives us a numeric date - in the format yyyyMMdd REM which is useful in filenames for sorting set TODAY=%yy%%mm%%dd%
REM go to first directory containing something to backup REM tar it up, and move it to a backups directory cd "C:\\Documents And Settings\\Administrator\\My Documents\\bLADE My Documents\\" "C:\\cygwin\\bin\\tar.exe" -cvf %TODAY%_gtd.tar WM_Wiki_Pages move %TODAY%_gtd.tar "..\\My Personal\\WMWiki Backups\\."
REM repeat as required cd "C:\\Documents and Settings\\Administrator\\My Documents\\My Personal\\" "C:\\cygwin\\bin\\tar.exe" -cvf %TODAY%_ref.tar "My WM Wikis" move %TODAY%_ref.tar "..\\My Personal\\WMWiki Backups\\."
REM finished! go back to where we started cd %DIR_TO_RESTORE%
REM end scope for environment variables ENDLOCAL

(more…)