Thursday, September 12, 2013

Access Violation in CPropertySheet::DoModal

One "feature" about MFC that has always annoyed me is when you create a wizard or property sheets, calling CPropertySheet::DoModal results in an access violation.  This problem is discussed in detail in Q158552.  In short, MFC tries to modify the dialog template, but the dialog template is stored in a read-only page.  This results in an exception.  The operating system catches this exception, changes the page to read/write access, and tries again.  So really this is just a nuisance if you're debugging your application because it breaks on the exception every time.

Well, turns out it can be more than a nuisance.  If you're testing with Microsoft Application Verifier enabled, you cannot debug your application further.  AppVerify is designed to catch buffer overruns by using read-only memory pages.  So when CPropertySheet::DoModal attempts to write to a read-only page AppVerify steps in and puts a stop to the show with a "VERIFIER STOP 0000000000000002" error.

So how can you get by this?  You could disable AppVerify, but testing with AppVerify enabled is a good thing.  It helps you catch other bugs that would normally go undetected.  But I found a simple technique that allows you to keep AppVerify enabled.  Use Visual Studio's resource editor to change the font of the wizard pages.  The default font is "MS Shell Dlg."  You can change this to any font, but I recommend "Tahoma" as this is the font the Visual Studio resource editor uses when the dialog is set to "MS Shell Dlg."  This means your dialog units will be the same which makes arranging controls easier.  Other good font options are "MS Sans Serif," "Microsoft Sans Serif," or "Arial."  These are also generic fonts with the same or similar dialog units.

The reason this works is because of what MFC does.  It checks the font of the wizard/property page and if it doesn't match the font of the wizard/property sheet, it makes a copy of the dialog template and changes the font back to the system default.  This new dialog template is read/write so when processed inside CPropertySheet::DoModal it won't cause a problem.  And if you're following along, changing the font of the wizard/property pages will not change your product at all.  Since MFC changes the font back to the default it doesn't matter what font you change it to, the look and feel of your product will not change.

Thursday, August 15, 2013

The Number Sign

In today's short and very random post, I wanted to talk about the number sign (#) - in particular the different names.  This symbol has at least three different names; 1) number sign, 2) hash, and 3) pound sign.  The official name (at least in North America) is "number sign."  In Europe it's called "hash."  What's interesting is most Americans call it the "pound sign" which is most likely because when used in the context of a telephone it's called "pound" or "pound sign."  But what's the origin of this "pound" name?

Let's start off by looking at the typical keyboard layout in North America.

You can see the number sign is located above the '3' key.  Now let's look at the United Kingdom keyboard layout.

If you look at the '3' key you'll see a different symbol.  This symbol (£) is called "pound sterling," or sometimes just "pound."

So the reason why the number sign is often times called the "pound sign" is because on the US keyboard layout the number sign takes the location of the pound sterling symbol.

Hopefully this gives you reason to ponder the next time someone says "pound sign."  That's an inaccurate name that probably dates back more than a century now.

Monday, April 22, 2013

Children's books

Now that we have two little kids in the house we're reading a lot of kids books.  I am absolutely shocked by how many kids books have typographical errors in them.

First off, kids books don't have A) lots of words or B) very long words.  [BTW, when I say "kids" I'm referring to 1 - 2 years old.]  So errors should be very easy to catch.  I'm an engineer and I'll be the first to admit my spelling and grammar are not the best.  So the fact that I'm catching all these errors just means there are most likely more errors that I'm missing.

Secondly, the whole idea behind a kids book is to help teach kids how to read and write.  How can kids be expected to grow up and speak proper English when the authors of their books can't even read or write.

So what are some of these errors you ask?  By far the biggest error is using the word till when they mean 'til. 'Til with an apostrophe is short for until, but so frequently the author uses till, as in "to till the soil."

Probably the second most common mistake is using round instead 'round (again short for around).  So the popular kids song goes, "the wheels on the bus go 'round and 'round."

Both of these errors are similar in that A) it involves contractions and B) both forms are legitimate English words which means you can't rely on a computer spell-check to correct the mistake.

And there are tons of other errors such as improper punctuation.  When listing 3 or more items use commas to separate them (or depending on the situation even semi-colons, but again we're talking about kids books so the list should never be so complicated as to require semi-colors to separate the items).

Most of the books we have were given to us as gifts or hand-me-downs.  There is no way I would ever spend money on a book like this in the store, I don't want to support authors who can't proof read something as simple as a kids book, or be bothered to have someone else check their work.

Wednesday, April 10, 2013

STL String Class

So it's kind of funny, I chose the name for my blog because I'm a software developer, and yet very few posts deal with computer programming.  But today's post is very much about computer programming.

My preferred programming language is C++.  When working in C++ you pretty much need a good string class to help out.  One of my favorite string classes is the MFC class CString.  The downside is it's only available to MFC apps and sometimes you're developing non-MFC apps, or writing for other platforms.  Another common string class is the Standard Template Library (STL) string classes; std::string and std::wstring.  However, I've found the STL string classes to have some major drawbacks.  I have two main problems with these classes.

1)  They implement few useful functions compared to other string classes.  The STL string classes do not offer the ability to A) perform case-insensitive searches and compare, B) format a string like printf, C) lowercase/uppercase a string, or D) tokenize a string using delimiter characters just to name a few.  These are all very common tasks and the STL string class doesn't implement them.

2)  The second problem is a crash bug that shouldn't be.  Take the following code for example
char *sz = NULL;
std::string str(sz);

This code will result in a crash 100% of the time.  If you pass NULL into the constructor of an STL string it will crash.  This shouldn't be.  A string class that accepts pointers should check them for NULL before dereferencing them.

The STL string class has a few benefits.  First, it's pretty much ubiquitous these days.  Every C++ compiler includes a version of the STL library so you can always count on it being there.  Also, whereas it doesn't offer many advanced functions it does offer memory management and the most basic of functions.  So it's better than nothing.

I think what shocks me the most about the STL string classes is how poor they are compared to the rest of the STL.  The STL container classes like vector, list, and queue are extremely well written and I use them a lot.  So I would have expected the string classes to be better than they are.

Even though CString is my preferred class, I actually use a different string class in most of my projects.  Years ago I wrote my own string class, which I've continued to improve over the years.  It is pretty much the best of all the string classes I've come across.  The function names very closely follows that of CString.  I've also profiled the class for performance against both CString and STL.  The STL (because of it's simplicity) is faster than CString.  My class is as fast or faster than the STL.  Plus I've added additional functions I've felt CString was missing such as constructors that perform printf style formats.  So it's the best of both worlds; the speed and performance of the STL string classes, with all of the functions in CString and then some.  I guess the only downside to the class is it calls some Windows APIs and therefore is not cross platform.  But other than that it's a really nice, fast, and stable string class.  I truly wish I could upload this class for everyone to use, but alas I developed it at work which makes it the property of my employer.

Monday, April 8, 2013

Helium

Recently we had a birthday party for our 2 year old.  As with many parties for kids we had Helium-filled balloons.  But part of me feels like this was a horrible waste of a useful resource.  I know, that sounds a little odd to regret buying Helium-filled balloons, but let me explain.

As anyone who's taken chemistry knows, there are only two gases lighter than the average density of air; Hydrogen and Helium.  Because Hydrogen is highly inflammable (think Hindenburg), balloons and dirigibles are now filled with Helium.  But people don't realize Helium is a precious commodity that, depending on how you look at it, is NOT renewable.  When Helium is present in the atmosphere, because it is lighter than air, it rises.  It continually rises higher and higher in the atmosphere until eventually it bleeds off into space.  The same is true of Hydrogen, but Helium (unlike Hydrogen) is chemically inert so it can't react with anything making it heavier and thus keeping it in the atmosphere.  What this means is once Helium becomes airborn, it's only a matter of time until it's gone.  Helium is the second most abundant element in the universe, but it's extremely rare on Earth.  Only 5 parts per million of the atmosphere is Helium, and most of that is in the extreme upper atmosphere where we currently don't have the ability to extract it.

You might be asking yourself, if Helium is so rare in the atmosphere how or where does the Helium we use come from?  It may shock you to learn Helium is extracted from the ground, in the exact same way as natural gas.  There is Helium trapped in layers of rocks underground which is extracted and separated from other gases.  I believe up to 10% of raw natural gas underground is Helium.  If you're wondering how the Helium got in the ground in the first place, it turns out Helium is the by product of radioactive decay of several large elements such as Uranium.  That's why, to some degree, Helium could be considered a "renewable" resource because even though we take Helium out of the ground, there's always elements decaying creating more Helium.  That said, I highly suspect man is extracting Helium and using Helium at a greater rate than it's being created.  And that's why I feel like the Helium-filled balloons were such a waste.  We used Helium strictly for decoration when Helium has so many other uses such as cryogenics, dirigibles, inert gas environments, etc.  So in the future if I need MRI medical scan but the MRI machine isn't operational because there is no Helium to cool the super-conductive magnets, I'm sure going to wish I didn't waste the Helium on balloons.

Friday, March 29, 2013

AntiVirus Software


For a while now, a big topic in the tech industry is antivirus software.  With so many viruses, trojans, and malware out there, you need to do something to keep your computer (and it's data) safe on the Internet.  The general consensus is you need a good antivirus program.  But I'd like that challenge that assumption.  I got my first computer in 1994 and I've been on the Internet since day 1.  In the past almost 20 years I have never had a virus attack my computer.  But this wasn't because of really good antivirus software running on my computer - the truth is I have never installed AV software onto my computer.  I've managed to stay virus-free strictly through safe computer practices and commonsense.

Before I talk about how I stay safe, I wanted to briefly talk about the history of computer viruses and antivirus software.  In the 80s and 90s, computer viruses were spread from computer to computer via floppy disks (as the Internet didn't really exist).  At the time pretty much all viruses would destroy your data or make your computer useless until you reinstalled the operating system.  Starting in the late 90s, virus writers learned that there is monetary value to the data they were destroying.  The data might contain credit card numbers, bank accounts, a list of email addresses that can be sold to others, etc.  They could even "hijack" a computer and use it to attack others.  So the goal of virus writers had pretty much changed 180 degrees during.

As for antivirus software, in the 80s and 90s your choices were very limited, and few of them were free.  But as long as you were careful about what floppy disks you stuck into your computer you were pretty much safe.  Soon the now heavyweights of the industry (Norton, Symantec, McAfee, etc.) released good AV software.  But once your software was out of date, you might as well be unprotected.  Moving into the 2000s and they offered online subscriptions that kept itself up to date (so long as you kept giving them money).  Fortunately nowadays there are a ton of good free options out there including Microsoft Security Essentials, Avast, AVG, Ad-Aware, MalwareBytes, and Avira just to name a few.

But I personally can't recommend any antivirus program regardless of cost.  Why you ask?  Simple, all antivirus software suffers from the same problem - loss of system performance.  In order for antivirus software to function properly it needs to be fully integrated into the operating systems.  It's not enough to scan files, it must "watch" what every program is doing on the system at all times and be ready in an instant to stop a program it deems to be suspicious.  This level of integration means everything on your computer runs slower.  I wish I had benchmark numbers, but installing any AV program significantly slows down your computer!  In fact, I've often said that having AV software installed on your computer is only slightly better than having a virus on your computer.

Despite this system impact, AV software is just a necessary evil, right?  Well, there have been a number of articles released in the past year or two (from technical places like Toms Hardware) that question the effectiveness of AV software.  They found most AV software does not fully protect the user but in fact only gives the user a false sense of security (in addition to slowing down everything they are doing).  So why not ditch AV software altogether and replace it with good practices and commonsense?  That's exactly what I've done for almost 20 years.

So what exactly am I doing (or not doing)?  For starters, be careful what you download and run.  I'll only download and run software from trusted sites (Microsoft, Adobe, Google, etc.).  If there is a file I wish to download and run but I don't know the site, I will first download and install the file inside a Virtual Machine.  That way if the file ends up being a virus it cannot infect my machine.

Secondly, protect your browser/email program against infection, since most viruses will enter your machine via web page and/or email.  For the love of God don't use IE or Outlook.  These are the most targeted and insecure pieces of software.  I recommend Firefox and/or Chrome for a browsers and Thunderbird as the email client.

Next, it's important to keep your computer and all it's software up to date.  On a regular basis run Windows Update as well as updates for other software (such as your web browser, email, Flash, etc.).  There's nothing worse than getting a virus simply because you were running an older version of a program.

The last step is to protect your computer against forced attacks.  Other than keeping your computer up to date, the most important thing is to run a firewall.  If your router has a built-in firewall, enable it (and make sure your router firmware is up to date while you're at it).  Chances are, that's all you need to do.  You can run a firewall on your computer itself - it's just redundant.  I disable firewalls when I'm in my home network (as I trust all my computers), but I enable firewalls when on strange or foreign networks.  Unless you do a lot of home networking, just enable the firewall on your computer and be done with it.

There you go, those simple steps should allow you to be safe on the Internet without the issues associated with AV software.  Oh, if you're wondering "how do you KNOW you've never had a virus if you don't run AV software?"  Easy - there are simple ways I am willing to double-check my computers for viruses without suffering the problems of AV software.  Those methods are:

  1. On average every 2 years I reinstall the operating system on my computer.  Before reinstall the operating system but after backing up my data, I install one or more AV software programs to my computer.  This allows me to scan my system and verify I'm still virus free, and since right afterwards I reinstall the operating system the AV software is completely blown away.
  2. I can boot my computer into read-only mode using what's called Windows PE.  From WinPE I can scan my files to ensure there are no viruses.  And since this is read-only mode, when I boot my computer normally the AV software is gone.
  3. About once a quarter I backup my data onto an external drive.  I can then plug that drive into a test computer (or Virtual Machine) with AV software installed and again scan my data.

I hope I've challenged the conventional thinking about AV software.  You can be perfectly safe without an AV program installed.  If however you absolutely must install AV software, might I suggest a program that allows you to disable real-time protection and only perform a scan at your request.  Microsoft Security Essentials has such a feature, but I'm sure others do as well.  This is a good compromise as you get some protection but without all of the system impact of real-time monitoring.

Thursday, March 28, 2013

Sci-Fi Review - Star Trek: Deep Space 9

Last time I talked about ST:TNG, so the next show in succession would be Star Trek: Deep Space 9 (herein referred to as just "DS9").  DS9 is definitely a show I've had mixed opinions about.  When it first aired in 1993 I watched the first season or two before I lost interest.  I think what turned me off was how radically different DS9 is from TNG.  Whereas TNG takes place on a Federation starship exploring the galaxy, DS9 takes place on an alien space station.  Very little technology is Federation, and many of the characters aren't Starfleet.  To me these changes were just too much and I stopped watching the show after the first few seasons.

Years later I went back and rewatched DS9 and it was then that I realized these differences were actually the shows strengths.  I believe the best aspects of DS9 are the character developments as well as the story writing.  Because the location and character differences between DS9 and TNG it allowed for stories that would never have worked in TNG.  TNG is set inside the Federation which depicts this perfect human future where crime, poverty, and disease are pretty much gone.  Compare that to DS9 which is set in an alien space station with many non-human races which allowed for "darker" plots and characters developments such as cheating, stealing, murder, betrayal, war, etc.

As for the cast, you have the leader in the form of Benjamin Sisko.  Sisko is a big departure from Picard (and not just because he's black).  Sisko is a widower and a father.  We also discover quickly that he is a religious icon to the Bajorans.  I think Sisko's character took a few years to get going.  But in later seasons you see the depth of his character and the acting ability of Avery Brooks.  There are even episodes where Sisko makes very un-Federation decisions such as lying, cheating, and even being a party to murder.

Kira Nerys is second in command and a Bajoran.  She grew up a terrorist fighting for her freedom.  She has some violent tendencies just like Worf (which is a trait I didn't care for), but unlike Worf they don't bother me in her character.  I think it's because Kira is trying to change her ways and forget her past.  On DS9 Kira kind of represents the "religious" aspect, which is another departure from TNG.  TNG was all about cold hard technology, a future where religion is seemingly gone.  But with Kira and the Bajorans they bring an religious element to the show which is nice to see.

Jadzia Dax is the science officer on DS9.  Dax is kind of the voice of reason, knowledge, and experience.  She is a non-human species and has the memories of multiple previous lifetimes.  This is used to write good episodes, but unfortunately sometimes they wrote so rather bland episodes based around this.  As a result, my feelings about her character are definitely mixed.  I never did understand why she left the show with one season left.  Did she choose to leave or was she written out?

Julian Bashir is the young and very eager doctor on the show.  He is one of my more favorite characters, especially in later seasons when it's revealed he was genetically altered as a child (which is illegal in the Federation).  So Bashir's whole character is a contradiction in the "perfect" TNG Federation.  But his "super-human" abilities make for some great story lines.

Miles O'Brien is a supporting character they brought over from TNG.  I was so glad they did this as his character is so likable.  He represents the "everyday man."  He's married with a family.  Another big distinction is he's not an enlisted officer in Starfleet.  They did a lot of great stories around O'Brien, many of which seemed to be to his detriment - such as being accused of a crime he didn't commit, forced to endure prison time for a different crime, and being hunted down and attempted to be killed for no good reason.  The characters of O'Brien and Bashir had a great onscreen rapport.

Odo is the stations shape-shifting security officer.  I think he was mainly written into the show to showcase the recently created CGI ability to morph characters and shapes.  At the time this was groundbreaking and had only been seen in big-budget films such as T2.  I liked Odo's character as one who likes order and is puzzled by social interactions.  I guess you could say he's a fastidious introvert - something I can totally understand.

Being added to the show halfway through, Worf is the second character to be brought to the show from TNG.  I didn't care for Worf in TNG, but his character is a little more likable in DS9.  I think it's less that his character is likable, and more than the introduction of his character made possible additional stores such as the war with the Klingons.

Quark is the station's Ferengi bartender.  Quark epitomizes everything the Federation is not; lying, cheating, stealing, gambling, drinking, sex, manipulation, extortion, etc.  But his character is so much fun on the show.  The constant cat and mouse game between him and Odo is fun and even serves to lighten the mood of the show.  Odd that is takes such a "dark" character to lighten the mood and bring humor to an otherwise dark show.

Jake is Sisko's son and one of those characters that didn't get as much screen time as he deserved.  He did have the ongoing friendship with Nog (a Ferengi) which served to show that even in this less than ideal location people could overcome their differences and befriend others.  I liked that the writers took Jake in a different direction - it was expected the son of a Starfleet captain would himself join Starfleet, but he didn't.

Ezri Dax was written in to take the place of Jadzia after she left the show.  Even though she was only on the show for 1 season, it felt like a large number of the last season's episodes revolved around her.  This included love affairs with both Bashir and Worf.  Ezri was not a favorite of mine.  I found her character to be a little whiny at times.

The last character I want to talk about is Elim Garak.  I guess you could say I literally saved the best for last as Garak is easily my favorite character in DS9. Technically Garak is not a main cast member but a supporting cast member - although he's probably in at least half of all DS9 episodes.  Garak is the ultimate mysterious character.  He's a ex-spy which means by nature he doesn't want to discuss his past.  So you learn bits and pieces about his character over the 7 years of the show.  He has some of the best lines such as "lying is a skill like any other - and if you want to maintain a level of excellence you have to practice constantly."

Of course, no analysis of DS9 would be complete without mentioning the war with the Dominion.  The Dominion was introduced at the end of season 2 and became the single largest ongoing plot in the show.  The Dominion is one of the most well-crafted foes in any show.  The main antagonist is actually 3 different species of aliens.  The Dominion is portrayed as technically superior to the Federation which puts the Federation is a uphill battle to the very end.  These episodes are griping and powerful and one of DS9's best attributes.

Another big change with DS9 was the introduction of large plot lines spanning multiple episodes.  In TNG no plot line spanned more than 2 consecutive episodes.  But with DS9 they wrote plots that spanned 10 or more episodes - making the war with the Dominion possible.  Yes this is more common nowadays (e.g. Lost, 24, and Prison Break), but back in the 90s few TV shows did this.  Broadcasters were afraid that by having such long plot lines that unless people started watching at the very beginning they wouldn't choose to start watching a series in the middle for fear of being lost and confused.

With everything I loved about DS9, there were a few things I didn't care for.  Later on they introduced the character "Vic Fontaine."  He's a holographic singer/performer set in the 1950s/60s.  Ugh, these episodes are so boring.  And any of the episodes where they visit the parallel universe are bland.  But other than those two exceptions, DS9 has really good writing.

My favorites DS9 episodes are "Paradise," "The Wire," "Civil Defense," "Improbable Cause" / "The Die is Cast," "The Visitor," "Statistical Probabilities," and all of the Dominion story arc episodes.

So that's my rundown of DS9.  Easily one of my favorite shows, just a hair below TNG on my all-time favorite shows list.  If you're a Star Trek fan and you've never seen DS9, or if you didn't care for it and stopped watching, I encourage you to give it another try.