VHD Attach 3.30

VHD Attach screen

VHD Attach is updated once more.

One personal annoyance is finally fixed. It was always difficult for me to find auto-mounted disks. I auto-mount them right after installation and then, month later, I cannot find where they are exactly. Now all those disks will be added to list of recently used files.

With that sorted out I proceeded with adding taskbar progress for creation of fixed drive. Funny thing that someone who wrote how easy adding it to your application can be took sweet time to do it himself. Regardless of shame, now operation progress can be checked with just quick taskbar glance.

For detail-obsessed there is parsing of dynamic disk header. Not much, but it will make someone happy.

Of course there was some generic bug bashing but let’s not get into it.

Check pages for download or use built-in upgrade.

[2012-05-31: Yes, there is bug-fix out already. :)]

DebuggerDisplay Can Do More

Illustration

Quite often I see code that overrides ToString() just for the sake of a tooltip when debugging. Don’t misunderstand me, I like a good tooltip but, if that is single reason for override, there is other way to do it.

.NET has [DebuggerDisplay](http://msdn.microsoft.com/en-us/library/x810d419.aspx) attribute. Simple class could implement it like this:

[DebuggerDisplay("Text={Text} Value={Value}")]
internal class XXX {
    public string Text { get; private set; }
    public float Value { get; private set; }
}

And that will result in debugging tooltip Text="MyExample" Value=3.34. Not too shabby. But what if we want our display without quotes and with different rounding rules?

There comes in expression parsing part of that attribute. Anything withing curly braces ({}) will be evaluated. So let’s change our example to:

[DebuggerDisplay(@"{Text + "" at "" + Value.ToString(""0.0"")}")]
internal class XXX {
    public string Text { get; private set; }
    public float Value { get; private set; }
}

This expression will result in tooltip that shows MyExample at 3.3. And I see that as an improvement.

Nice thing never comes without consequences. In this case advanced formatting is dependent on language used. If you stick to single language you will not see anything wrong. However, if you mix and match (e.g. C# and VB) you might end up in situation where DebuggerDisplay expression is evaluated by language currently being debugged regardless of language which it was written in.

I usually ignore that risk for sake of convenience.

P.S. And anyhow worst thing that could happen is not seeing your tooltip in very rare situations. Your actual program will not be affected in any manner.

OSH Park

Illustration

PCB designers rejoice, there is new player in town and it’s name is OSH Park. It is yet another batch PCB service that will try to get it’s place under the sun.

Oh, no, wait. This is not a new player. Good old Laen’s PCB Order got a face-lift.

To reiterate a bit. You still get really nice purple boards. You still can have 2-layers with 6/6 mil traces. ENIG finish seems to be a unwritten standard (I don’t recall last board that I got without it). Panels go out every second day. All in all, it is as good as it can get. And all that will cost $5 per square inch for three boards. On PCB side there is hardly any place for improvement (slots, please). Single new thing here is website.

Interface is very simple and that has it’s benefits. If you have single big button named Select a file, there is very small chance of things going wrong. Once zip file gets uploaded, content is analysed and you get nice pictures for all gerbers along with how system recognized them. After approving project, only step that remains is to make an order.

It is definitely not a revolution and there are quite a few PCB manufacturers with such system in place. But it is not worse either.

Web site is very new and there are bugs. There are obviously missing features (e.g. deleting a project). Not even all content is moved from old pages. It will take quite some time to bring everything to a level of service I came to expect from old e-mail based ordering system.

However, my recommendation still stands: If you are hobbyist in search of excellent PCB manufacturer with good price, search no more.

P.S. And purple boards do grow on you. :)

Programming Windows

Illustration

One book that brought me into Windows programming was Programming Windows by Charles Petzold. While examples were C-based actual theory was mostly language-agnostic. APIs tend to work the same whether you do it in C or VB.

If you had any interest in Windows API, I do not think that there was a better source at the time. Unfortunately this great book died after 5th edition (Windows XP based).

Well, book is back from retirement and this time it deals with Windows 8. It will be published in November at price of $50. However if you buy it before May 31st 2012, you can grab it for a $10. I would call that a good deal.

I already ordered my copy.

P.S. I must warn you that this book is very distant relative to original series at the best. Instead of low-level programming you will get XAML and panes. However, Petzold is known for good books and that alone should justify $10.

P.S. If you are interested in real C++ programming book, do check Professional C++.

CA2000 and Using Statement

I started with code like this (give-or-take few white-spaces):

using (var aes = new RijndaelManaged() { BlockSize = 128, KeySize = 256, Key = key, IV = iv, Mode = CipherMode.CBC, Padding = PaddingMode.PKCS7 }) {
    this.Transform = aes.CreateEncryptor();
    this.Stream = new CryptoStream(stream, this.Transform, CryptoStreamMode.Write);
}

Running code analysis on this returned [CA2000](http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&k=k(%22DISPOSE+OBJECTS+BEFORE+LOSING+SCOPE%22)) (Microsoft.Reliability) error. It simply stated “In method ‘Aes256CbcStream.Aes256CbcStream(Stream, CryptoStreamMode, byte[])’, object ‘<>g__initLocal0’ is not disposed along all exception paths. Call System.IDisposable.Dispose on object ‘<>g__initLocal0’ before all references to it are out of scope.”

Problem here is that all object references ARE being released by using statement. Or so I thought.

If you are using Object Initializer, compiler will generate code to support it. And that compiler-generated code is culprit for that message. And yes, there is a reason for why it behaves like this.

Personally I often ignore this warning. Strictly speaking this is not a real solution and definitely not a best practice. However it is quite often acceptable. If you are generating just few of these objects and there is no failure expected (famous last words), little bit more work for garbage collector is acceptable scenario.

Real solution for now would be not to use Object Initializer syntax when dealing with using statement. In our example that would mean:

using (var aes = new RijndaelManaged()) {
    aes.BlockSize = 128;
    aes.KeySize = 256;
    aes.Key = key;
    aes.IV = iv;
    aes.Mode = CipherMode.CBC;
    aes.Padding = PaddingMode.PKCS7;
    this.Transform = aes.CreateEncryptor();
    this.Stream = new CryptoStream(stream, this.Transform, CryptoStreamMode.Write);
}