New Compilation Constants

Sat, April 30, 2005, 05:45 PM under Whidbey | VisualStudio
Dotnet projects have at least two configurations: Debug and Release. Part of the configuration is the definition of two compilation constants: DEBUG and TRACE. For Debug configurations, both constants are on; for Release, only TRACE is on. I always turn TRACE off as well, and I advice you to do the same (however, that is not the point of this blog entry).

You can tweak these in your project properties (they are represented by checkboxes) and you can also add your own in the textbox offered or you can define them in code (#define or #const, depending on your language of choice). An example of why you would add a compilation constant is for cross platform development, as detailed before.

For conditional compilation you use #if. In C#, the code that does not apply gets greyed out. This is really sweet and somehow I thought it was added to the VB2005 IDE, but unfortunaly I realised recently it wasn't :-(
Go vote for it (maybe it will make the Orcas release).

In VS2005 we find a few additional conditional compilation symbols that are not in VS.NET 2003 (applicable or not, based on what project type you chose and what language you are developing in):

I'll let you figure out what each one is used for and the potential values they can have ;-)

Tiny (but positive) change

Fri, April 29, 2005, 01:09 PM under Whidbey | VisualStudio
Just noticed a infinitesimal change in VB code with Whidbey that will make copying pasting from C# to VB and vice versa require one less thing to look for.

As you know, code for properties in VB is autogenerated:
Public Property SomeProp As String [hit enter here]

The setter looks like this in VS.NET 2003:
Set(ByVal Value As String)

In VB2005 Beta 2 it looks like this:
Set(ByVal value As String)

Seems like the VB team had their ear pulled by the coding/naming guidelines department :-)

Are you in Ireland?

Thu, April 28, 2005, 09:30 AM under Events
Paschal announced this morning a new event for the Ireland .NET Developers Alliance (INDA).
UPDATE: Yes, that is me in the photo and no, I didn't down that in one go ;-)

Make sure you are in Dublin in July. Personally, I'll make a weekend of it, i.e. fly out with Jenny on the Thursday and come back on the Sunday. All I can think of is... Guinness :-)

Date: Friday 15th July 2005
Title: VS2005 & CF 2.0 Highlights
Summary: While most may have heard of Whidbey in the context of Yukon or ASP.NET 2.0, there is a lot in it for the Compact Framework developer too. CF 2.0 brings with it numerous enhancements and VS2005 provides a tailored experience for CF developers making them first class citizens of the .NET world. Come to this session and take a look at what's new in VS2005 and CF 2.0. Guaranteed to make you want to get your hands dirty with Beta 2!
Venue: Buswells Hotel in Dublin
Times: 18:30 start
Registration: Here
Price: Free

When the desktop and compact teams do not talk to each other

Wed, April 27, 2005, 02:59 PM under MobileAndEmbedded
While moving some of my cross-platform code from .NET 1.1/CF 1.0 (Visual Studio .NET 2003) over to .NET 2.0/CF 2.0 (Visual Studio 2005) Beta 2…

… the desktop compiler warned me that the following method was obsolete:

No problem, as the helpful warning informed me of the replacement method, so I change my code and it compiled:

I then open my Smart Device project and I encounter an error that GetHostEntry is not recognised (the method is not supported by the CF version of Dns)! I look the class up and it supports Resolve without any obsoletion warning in sight!

The temporary solution is conditional compilation, but I am confident that by RTM the CF team will resolve (no pun intended) this :-)

Intellisense for CF v2.0

Tue, April 26, 2005, 12:52 PM under MobileAndEmbedded
We looked last time at the VS.NET 2003 support for Smart Device Projects from an intellisense perspective.

VS2005 seems to be miles ahead in that department (as well). In fact, I have yet to find a PME (property, method, event) that compiles while it is not supported _or_ a PME that is supported at runtime and not offered in the IDE :-)

The story is even more interesting. Let's take a control, e.g. TreeView. If you try to add an event handler in code, intellisense lists only the events that are applicable. Now, since TreeView inherits from Control, I know I should be able to add an event handler to an event that is exposed by Control such as DoubleClick or Paint. So, even though intellisense doesn't help me, I can type:
treeView1.DoubleClick += new EventHandler(treeView1_DoubleClick);

Here is the new feature. This does not result in a compilation error but rather a warning in the "error list" window:
"Members not supported by the Device platform should not be called: System.Windows.Forms.TreeView.add_DoubleClick is not a supported method in this platform".
I like this! If I have explicitly written code that intellisense doesn't recognise I must have my reasons, so don't error out on me - just warn me. E.g. if code is shared between desktop and CE devices, you may avoid the conditional compilation and just not offer the functionality on the CE device. (this does make me think of a feature request to turn every compilation error into a warning, but I'll resist going down that thinking path...)

Needless to say that if you try something like adding an event handler to TreeView.NodeMouseClick event, which is supported in .NET 2.0 but not NETCF 2.0, you do get a compilation error; the warning in the previous case is only because the event is inherited from Control.

Intellisense for Smart Device Project v1.0

Mon, April 25, 2005, 03:13 PM under MobileAndEmbedded
When writing Compact Framework code with VS.NET 2003, intellisense is smart enough to filter out the framework methods that do not apply to the CF. Truth be told it could be better. There are some properties shown that are not supported by the CF, yet they compile, and hence you only find out at runtime. Some of them will result in runtime exceptions (e.g. changing the Font of a UpDown control) and others will silently do nothing and have no effect (e.g. changing the Size of a StatusBar). I am not sure which outcome is worse, but I do know the methods should not have been available in the IDE in the first place, since a Smart Device Project was chosen! The help is pretty good (but certainly not perfect) at pointing out which class members are applicable to CF.

The area where the IDE is really bad is events. C# shows in the properties window the events that are applicable, but some events are shown even though they are not supported (e.g. PictureBox.Validating) and others are supported and not shown (e.g. PictureBox.Click). In the latter case the workaround is to manually add the events in code (in code there is no filtering so, whether applicable or not, the compiler lets you add event handlers). VB is much worse. As you know, the event handlers are generated by selecting the event names form the top right combobox in the code view; well that combo doesn't even make an attempt at filtering! In case you think the documentation will come to your rescue, think again: the documentation makes no statement about the applicability of events to the CF or not.

To complicate things further, there have been 3 service packs for CF 1.0 and all of them apply to the runtime *not* the VS IDE. Since the SPs, some properties (e.g. BackColor) are available. None of these are shown in the properties window but you have to manually use them through code.

At this point you might be expecting me to offer some solution. Sorry, but there is only one way to face this issue: try out your code before you make assumptions about what is supported or not.

VS2005 is a whole different (more pleasant) story and we'll look at that next time.

Blog link of the week 16

Sun, April 24, 2005, 02:53 PM under Links
Your CF 1.0 app can run against CF 2.0 in compatibility mode or not. Learn how here

Target the v1.1 framework with VS2005 Beta 2

You can unwind exception call stacks

Do you agree that .NET is the best thing since OO?

This isn't the first and it won't be the last but, judging at how many times the question gets asked, it is needed: WinCE vs WM

Funny :-D

.NET Compact Framework for desktop developers

Tue, April 19, 2005, 04:20 AM under Events
Looking forward to seeing you there

Date: Thursday 30 June 2005
Topic: VBUG Technical Meeting with Daniel Moth MVP
Overview: Have you got some experience as a .NET developer but have done very little or nothing with the .NET Compact Framework? This session will whet your appetite for Compact Framework development and will allow you to hit the ground running on your 1st project. Whether you write in C sharp or VB.NET, whether you are interested in Pocket PC, SmartPhone or custom Windows CE devices, come learn how the NETCF can be used and where it differs from its big brother. Bring your tough CF Qs or sit back and enjoy the demos
Venue: Horsham District Council, Park North, North Street, HORSHAM, RH12 1RL
Times: 18:30 arrival for 19:00 start
Registration Details: Email or call 01753 648555
Price: Free to members

Blog link of the week 15

Sun, April 17, 2005, 02:39 PM under Links
+ Everybody and their dog know that VS2005 Beta 2 is out on MSDN so I will not link to it. Early experience descriptions are aplenty and the lengthiest one I came across is here.

+ I wish I had the chance to attend that lecture as this post whets my appetite.

+ Some folks are brave living in a multi platform world. I found these two posts interesting. (Recollections of a previous life spring to mind: "write once debug everywhere" a.k.a. Java development)

April MVP chat

Tue, April 12, 2005, 03:19 PM under Events
Yet another .NET Compact Framework MVP chat took place earlier today. Once again we left no question unanswered whilst a couple of times we had to refer folks to post in the newsgroup.

Probably worth stating the obvious here: Bring *any* question to the newsgroup and *any* question to the chats. However, questions best answered in the chat are those that can be formed in 1-3 sentences; anything longer implies the reply will also be longer and hence the newsgroup is a better fit (even more so if questions/answers include sample code). Just my humble opinion...

By the way, I am surprised I have not seen any chat announcements/references on fellow MVP blogs outside the Compact Framework. Don't e.g. VB/C#/ASP.NET MVPs host chats? I wonder of this is a Windows Embedded thing only...


Mon, April 11, 2005, 02:56 PM under MobileAndEmbedded
Recently I needed to change scrollbar colors, the disabled text color and other similar items. The target is a Windows CE device (not a PPC) and I quickly found (through the control panel) the Display Properties dialog and specifically the "Appearance" tab. If you don't have a WinCE device, launch the 4.1 emulator that ships with VS.NET 2003 to check it out.

So there was my goal: to find out what it does under the covers in order to offer us changing colors of individual items (e.g. Active Title Bar color) and also the overall scheme (e.g. Brick). We start at the obvious place: *everything* on this platform is stored in the registry. Using the Remote Registry editor (that comes with eVC) we take a snapshot before and after a scheme change and then use windiff (or similar) to spot the difference. Bingo; we find a string value "Current" under HKCU that stores the scheme name and, more importantly, we find a byte array value "SysColor" under HKLM that stores the color data. Searching on MSDN proves fruitful and informative, leading us to this and this. We test out our understanding by changing some of the RGB values in the registry, flush, reset the unit and the changes take effect. Nice!

Next step is to figure out how the control panel applet applies the change on the fly. We suspect some windows message and decide to investigate further with another eVC tool, remote spy++. Every time we apply a change a WM_SYSCOLORCHANGE message is broadcast. So we try with our own app to change the registry and then broadcast the same message but no effect takes place. Wouldn't it be great if we had the source code to the OS dialog so we could see exactly what it does? But wait, I have platform builder installed on this machine, so I could locate the code and check it out! After a few hit and miss searches, I nail it down. They call an API that does both the writing to the registry and the broadcast and the on-the-fly change: SetSysColors

Note that, if you don't care about changing colors and all you need is read-only access, then the existing System.Drawing.SystemColors class fits the bill.

This has been a not so short story, leading up to providing you with a managed class that wraps all of the above. Use it in your own WinCE (not-PPC) projects for changing color themes on the fly or single element color changes.

Download the VB class here.
Get the C# version as part of the SDF (guest, guest).

Blog link of the week 14

Sun, April 10, 2005, 03:55 PM under Links
As a "lover" of nntp I can't say I was immediately happy about this, but if properly managed it could end up being fantastic for Visual Studio 2005 developers everywhere and the beginning of a new way to get/give help: MSDN Forums Beta announced


Fri, April 8, 2005, 02:22 PM under Events
Mobile & Embedded Developer Conference

I'll be there! Come say hello at the Microsoft booth or at the "Ask The Experts" session.

Register Today

Early Bird Registration ends April 20


Mon, April 4, 2005, 02:02 PM under Personal
Honeywell acquired Novar.

This means that while previously my company was part of the Intelligent Building Systems division (of Novar), now we are part of Automation and Control Solutions (of Honeywell).

Notice that we were, and still are, Trend.

To any Honeywell employees out there reading my blog: "Hello colleague :-)"

Blog link of the week 13

Sun, April 3, 2005, 03:33 PM under Links
I've been considering this lately, so the advice in this article is very welcome.

:-D Reserved for whom?