c and c++ code Use C and C++ code together   undefined reference galoreIf word on the street is to be believed, C and C++ can coexist peacefully. Just include the C library<'s header into your C++ file, put them both in a project as seen on the left, and you are set to go.

Unfortunately, this isn't the case - things like polymorphism and other properties of C++ lead to loads of "Undefined reference" errors when trying to access C functions from C++ code and vice versa.

The solution consist of special extern directives - the two sites below should keep you covered:
Mixing C and C++ code in the same program
How to mix C and C++

Good luck porting!

Manhattan night view Design patterns for .NET CF, courtesy of MicrosoftMost books on design patterns and/or application architecture are insanely expensive and not particularly well-suited to the demands of mobile application developers.

Fortunately for us, Microsoft’s patterns & practices group has just released a freely-downloadable ebook called “Rich Client Architecture Pocket Guide”. The 1MB PDF file looks at all things mobile – if you feel like giving it a spin, hit the URL below!

Rich Client Architecture Pocket Guide

Image: Wikimedia Commons / Andyindia

.NET developers are blessed by not having to care about the joys of character representation on Win32-based platforms – while most other OSses (e.g. Palm OS) are limited to single-byte chars, our friends at M$’s have cooked up a variety of different types including Unicode.

One resource I personally found extremely useful was Michael Dunn’s two-part tutorial. It starts by looking at the memory representation of “advanced” strings, and ends at string conversions – find it at CodeProject’s:
The Complete Guide to C++ Strings, Part I – Win32 Character Encodings
The Complete Guide to C++ Strings, Part II – String Wrapper Classes

Microsoft’s MSDN unfortunately is very confusing when it comes to strings. Nevertheless, the Win32′s String Chapter contains a few useful articles (hidden under UI…as if anyone would look there) – hit the URL below for the full scoop:
Unicode in the Windows API

So far, I have had huge issues with my beta testers: the moment they removed Daily Quote for PocketPC, their PocketPC popped up a highly annoying alert about “File not found” whenever it powered up. Yikes. I have no idea why Windows Mobile can’t purge unneeded notifications like the Palm OS can – but hey, its Windows Mobile…

The ideal solution would involve a single API call being called at program removal: as the program gets kicked off the handheld, a single call is called, thereby eliminating any and all notifications still lingering around. Unfortunately, this is not possible with the .NET CF – the solution is called Setup.dll and requires native code. While I am completely dumbfounded as to why native code is required, the only reason I can think off is that Microsoft wants to make sure that the dll is run even if the .NET framework is not installed.

Jos̩ Gallardo Salazar has posted a lovely overview of the process to his blog Рhit the link below for the full scoop while I try to figure out how it all works:

P.S. A template for a custom Setup.dll can be downloaded here.

I often wonder what the Microsoft .NET CF team was smoking when it created the omission lists for the compact framework – many extremely useful calls were left out for some reason or the other (color picker, anyone?).

ComboBox objects usually contain a list of different unique strings – the little routine below implements the behaviour desktop developers find in the .FindString method:

Private Function findItem(ByVal cmb As System.Windows.Forms.ComboBox, ByVal text As String)
Dim index As Integer
For index = 0 To cmb.Items.Count - 1 'bc of weird beh index = index
If cmb.Items.Item(index).ToString = text Then
findItem = index
Exit Function
End If
findItem = -1
End Function

As usual: feel free to do whatever you feel like with this code!

Plucker is a classic and very useful documentation handler – I have generated a copy of the full Palm OS API reference years ago, and use it ever since. As Google’s Android developer documentation also comes as a bunch of HTML files, I felt that pluckering it may be useful.

Unfortunately, Plucker Desktop was not up to this gigantic task – after hours and hours of tweaking SunRise settings, I am proud to present the two shots below:
androidC5204889 Android documentation   Plucker friendly androidC52048A0 Android documentation   Plucker friendly

These images show a Treo 680 rendering the Android Documentation via Plucker! The file is 18MB large and should IMHO be placed on your memory card rather than in your phone’s RAM.

Hit this link to get the file!

P.S. Yes – this file really is a full pluck of Google Code’s /android/ folder…enjoy!

P.S.2 Use Vade Mecum to access Plucker files on your PocketPC!

Developers wanting to create panels that plug into Sony Ericsson’s “Sliding Panel homescreen” can now do so – the SDK has just been released. The requirements for the SDK are pretty humane – you need Visual Studio 2005, the WM6 SDK and the latest version of ActiveSync 4.5.

Unfortunately, Sony Ericsson does not specify which programming language(s) can/must be used to create these panels – I am pretty sure that .NET CF developers will be left out due to the way-too-long startup time of the CLR interpreter (up to three seconds on my rx4240).

Amusingly, the SDK ships with a full XPERIA simulator – should anyone of you feel like taking the box for a spin: this is your opportunity…

Further information can be found at Sony Ericsson’s developer network!

Like most other about screens, the about screen of HTC’s TouchFLO 3D app contains loads of gibberish that doesn’t really do anything except satisfy legal requirements. Enter Johan Sanneblad.

He took the time to “decompile” the text and found a stunning amount of open source projects which were used in the creation of HTC’s user interface.

People wishing for the full list can give Johan a click here:

I am currently working on “porting” my VB.NET test application from Pocket PC to Windows Mobile Smartphone(two binaries, but one code base) and have found the following links very useful. Treat it as a “collection of resources” for now – a detailed writeup comes in the near future!

Share Source Code Across Platforms (Devices)
This article gives you a broad overview at what’s needed.

Verify Platform Support for Code in Device Projects
A single line can kill your app – this article tells you how to tell the VB compiler to make sure that no “unedible” code is compiled.

Change Platforms in Device Projects
This little writeup tells you how to switch your Visual Studio between the two “platforms”…

If you find any other useful resources, please post them here!

Sometimes, UI designs demand text boxen to accept only numeric data(aka no characters) – after all, entering abc as a delay time value most definitely won’t make much sense. While the Palm OS allows developers to create so-called “numeric text fields” that only accept numbers, the .NET CF does not include this feature…

The code below restricts user input to the characters 1234567890 – no decimal points/commas can be entered:

Private Sub TxtX_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtX.KeyPress, TxtY.KeyPress
e.Handled = True
If Char.IsNumber(e.KeyChar.ToString) Then
e.Handled = False
End If
End Sub

Just paste it into the form’s code, and add the names of all numeric text boxen instead of TxtX and TxtY(you can have 1 to n).

Enjoy your numeric text box…

Palm OS handhelds have a lovely feature – whenever you insert a memory card, they look for a file called Start.prc and – if they find it – execute it automatically(sort of like the Autostart feature found on CD and DVD media). Windows Mobile devices can do that, too – but it is a bit more difficult.

Autostarting an application on a PocketPC can be accomplished by creating the following file/folder structure on a memory card:

The application file must always be called autorun.exe. The 4-number folder name defines the processor architecture(always 2577 for PocketPC) – here are numbers for other processor architectures:

HITACHI_SH3 10003 // Windows CE
HITACHI_SH3E 10004 // Windows CE
HITACHI_SH4 10005 // Windows CE
MOTOROLA_821 821 // Windows CE
SH3 103 // Windows CE
SH4 104 // Windows CE
STRONGARM 2577 // Windows CE - 0xA11
ARM720 1824 // Windows CE - 0x720
ARM820 2080 // Windows CE - 0x820
ARM920 2336 // Windows CE - 0x920
ARM_7TDMI 70001

Files are copied to the /windows/ folder and are then run from there – your Autorun application should thus be able to stand on its own….

Further information here:

I have recently had a pretty weird problem: I wanted to read multiple bytes from a StreamReader object. Unfortunately, the necessary command was omitted from the .NET CF version of the control. As this is highly annoying (IMHO), please allow me to share the following code snippet with you:

Private Function ReadMultipleBytes(ByVal howmany As Integer, ByVal reader As StreamReader)
Dim counter As Integer = howmany
Dim output As String = ""
While counter > 0
output.Insert(output.Length, reader.Read())
counter = counter - 1
End While
ReadMultipleBytes = output
End Function

Determining the line height of a font is very important thing for programmers creating applications that use changing texts as part of their UI. However, Microsoft(for some reason) decided to remove the .Height attribute from the .net CF Font object.

However, the height and width of a text can still be determined – if your code has access to a Graphics object. The object’s MeasureString method returns a SizeF parameter containing the height and the width of the string passed in….the values, of course, are in pixels!

The code example below creates a moving bar that permanently changes its color. In the middle of the bar, the text contained in drawString is displayed in white – this animated GIF simulates the effect:
sample Determine a fonts line height in .NET CF(.NET compact framework)

ElseIf Globals.Globals.TextMode = textmode_enum.series60 Then
Dim drawString As String = TextParser.getDateText
Dim myFont As New Font(System.Drawing.FontFamily.GenericSansSerif, 12, FontStyle.Regular)
Dim myTextBrush As New SolidBrush(Color.White)
Dim myBackBrush As New SolidBrush(Color.FromArgb(Int((254 * Rnd())), Int((254 * Rnd())), Int((254 * Rnd()))))
Dim y As Integer = Int(((MainForm.Height - 4 - gfx.MeasureString(drawString, myFont).Height) * Rnd()))
gfx.FillRectangle(myBackBrush, 0, y, MainForm.Width, 4 + gfx.MeasureString(drawString, myFont).Height)
gfx.DrawString(drawString, myFont, myTextBrush, (MainForm.Width-gfx.MeasureString(drawString, myFont).Width)/2, y + 2)
End If


P.s. If anyone of you knows how the MS boys format the code that they put onto their blogs so neatly….PLEASE let me know!
P.s.2 If anyone knows WHY Microsoft removed the Font.Height property from .NET CF, please let me know too!

While stumbling across the net in order to find a way to pick fonts in .net CF, I stumbled upon the following site offering a variety of interesting code samples:

While the page’s formatting probably is horrible, the examples found on it could potentially be helpful!

Do you know other pages containing .net CF sample code? If yes, please give us a holler!

The lack of a color picker dialog in the .NET CF(yes, the desktop framework has a ColorPicker class – but .NET CF doesn’t contain it) has annoyed hell out of me for quite some time – even the 10yr old Palm OS contains a well-done color picker. Anyways, problems are here to be solved – please allow me to present you my own ColorPicker(running in .NET CF 2.0 on a hp rx4240, blots are due to GIF compression):
scr A color picker for .NET CF

Using this is very simple – just download the form file here and integrate it into your project like you would do with any other form.

Then, do the following to make the user pick a color:

Dim colorX as color
colorX = ColorPicker.getcolor()

Feel free to do with this code whatever you feel like. However, no warranties are given on anything….and posting a link to an app that uses it always is appreciated!

© 2013 TamsPPC - the Windows Phone Blog Suffusion theme by Sayontan Sinha