I’ve been promising to get my son’s game running on a mobile phone for some time. When he was younger we spent some time writing a version of PacMan that we could run on his Nintendo DS, though this had to be written in C and we needed to use an R4 chip to allow us to boot the game on the hardware. He’s older now, with much grander ideas, so I spent some time looking at writing a game for Windows Phone 7 using Silverlight. The XAML skills I would have picked up doing this would have been useful, but the lack of portability to other platforms has been holding me back.
PhoneGap is great in that it offers a standard library which runs on the different variants of mobile phones, simulating library functions when they aren’t available natively. It still leaves the nagging question of how PhoneGap is actually implemented, so this weekend I pulled out Reflector and did some investigation.
The finished project runs inside the web browser instance, which is managed by the C# code in WP7GapClassLib.dll. PGView is the user control which wraps the web browser.
In order to understand exactly what it was doing, I wanted to write my own version, so I took a standard Silverlight project for Windows Phone, added a web browser control to it, and changed the property of the browser to make it scriptable.
The trick that PhoneGap uses, is to write the data from the resources into isolated storage, so that they are then accessible to the browser. We do the same in the following code, effectively simulating the PhoneGap start sequence.
This does sound like a very viable way to write an application though and I’m keen to start writing – I’ll let you know the result.