x2c source

I finally got around to putting up the source code for x2c under GPL. No, you haven’t heard of this thing and it may not seem immediately useful, but when it is useful, it’s incredibly useful. The hardest thing is coming up with full samples of what it can do, so I’ll just outline it right here.

x2c stands for “XML to Code”, and it’s an interpreter for a little language I made with built-in commands to handle XML documents and write to plain text output files.

It started life as a tool to create VB and C# source code for data access layer classes, based on XML descriptions of an Oracle database. Another possibility is generating language tables from Excel spreadsheets, and I’ll tell you how:

Imagine an Excel spreadsheet with one sentence per row. In each column, the same sentence is written in another language, like Swedish, English, French, etc. Save the spreadsheet as an XML document. Now you can write a pretty short x2c script that reads these languages, column by column, and then produces a C++ header file with the right strings declared as constants. Great for products you want to recompile for a number of human languages.

Especially for this last use, I recently adapted the text output file command in x2c to allow output to ASCII, unicode (default), or any codepage you have installed on the Windows system you’re running this thing on. In the above script example, you see codepage 1251 used for Russian. In this case this was necessary since the C++ compiler used (Borland) couldn’t use unicode header files. This script runs under US or Swedish XP and Vista, as long as codepage 1251 is also installed on the system, and then produces the right MBCS file for Borland C++, resulting in binaries that will look real to russians running russian versions of Windows. Note that above is the complete script that is needed to convert the excel spreadsheet to four different C++ header files and it can easily be run from a build script.

The source is C++ in a VS 2008 solution. Have a go at it.

MS is blazing the trail…

…on new innovative ways to make an install fail.

After upgrading my SQL server to 2005 SP2, I went to download the update for the Books On Line using the recommended link from the SP2 installer. Downloaded the msi to my desktop, double-clicked it and ran it. Then, after a while, got this message: “A network error occurred while attempting to read from the file:….”

Network error dialog
Network error dialog

“Network error”? Which “network”? The one between the screen and the desktop? Searched the web, found nothing. Started thinking deep. Read that message again and again and started noticing something weird about the filename. The file in the error message is called SqlServer2K5_BOL_Sep2007[1].msi, while the file on disk is called SqlServer2K5_BOL_Sep2005.msi, no “[1]” in there. So I renamed the file accordingly:

And lo and behold, the installer ran fine now! At a certain point while cleaning up temp files, it sits there spinning like forever, but that’s ok, normal MS behaviour, so don’t panic, it gets its knickers untwisted in due time:

The point of seemingly eternal wait
The point of seemingly eternal wait

Strongly typed constant parameters in C#

After a bit of searching, I found a way to have strongly typed constant parameters for C# functions. You know the situation, where you need to pass one of a limited set of strings or chars or other values to a function and you want to make sure somebody doesn’t just go and pass any old thing they find laying around the place. Enums are pretty good for this kind of thing, but it gets hairy if you need to translate it to anything else, like a string or a char.

Any solution also needs to pander to intellisense, making it easy to use and kinda idiot safe (I’m talking about myself a couple of hours after defining any constant, which usually leads to me behaving like the idiot user I had a hard time envisioning just hours earlier).

I think I found a good system for doing this, and as an example, I’ll invent a function that takes a string parameter, but it has to be just the right kind of string. To do that, I first declare the constant strings in a separate module this way:

Then I write my function, the fictional “Rechandler” that takes a parameter of the ConstRecTypeValue kind. And then I write a function that calls it. Now, while writing the caller, I want intellisense to do its thing, and it does:

As you can see, it obediently pops up a tooltip to tell me only a ConstRecTypeValue is accepted here. As soon as I start to type that, it recognizes the ConstRecType static class name and it intellisensively lets me choose which constant member I want:

…which I complete the usual way:

The callee (Rechandler) then easily recovers the string that is hiding inside the passed value (in this case “DELETED”) and continues its merry ways.

Naturally, you can use chars, doubles or entire collections of values instead of the string value in this example and still achieve the same effect.

You can also take it one step further along the path to universality, by using a generic base class for the value type:

If you have this guy in reach in your project somewhere, you can now simplify the definition of the value class like so:

…while everything else stays just the same.

I love it.

I found FindPart

Today I helped a neighbor recover data from his laptop. It wouldn’t boot and it ran (or failed to run) Windows XP. Checking it with a low level utility showed that the MBR and partition table were shot.

Now, Windows repair didn’t find the drive. Fixmbr didn’t fix the MBR. Fixboot didn’t fix the boot. Knoppix couldn’t mount the drive. Nothing worked.

So I pulled the drive from the laptop, hooked it up to my old, crappy, Dell Optimus, Octopus, or whatever it’s called, since it had SATA. Got the FindPart utility package, and man does that thing work right! The instructions aren’t exactly clear, but you can figure it out with a little patience. That stuff rocks! Highly, highly recommended.

MSDN going in circles

As I already mentioned, MSDN didn’t work. Talked to a “concierge” who told me it was an emergency maintenance gone wrong, that made downloads impossible. Now, I can’t even log on to the service. Funny, but if you try to go to the download areas, you start bouncing between msdn.microsoft.com and login.live.com. Back and forth, back and forth, until you get an error message. I made a little movie of the bouncing (yes, it’s Safari on OSX, but the same thing happens using IE on Windows.)

I’m not much impressed. Wonder when we’ll see MSDN alive again. BTW, shouldn’t MS use the “login.dead.com” service for things like this?

OMFG, what junk!

Had to install a Swedish XP under Parallels to test my product. I have MSDN Pro subscription, including operating systems, so I checked out my CDs and DVDs. No Swedish. Ok, so logon to MSDN Site for downloads. Um. The download link is greyed out for all products, with no explanation. All other links work. That’s under Safari on OSX, so I suddenly realize MS may not prefer to work anything under OSX and expecting them to tell you why it doesn’t work is probably too much asked. Ok, switched to an XP and sure, the links came alive.

Downloaded Swedish XP Pro with SP3. Tried installing under Parallels, but it ran into problems. Downloaded Swedish XP Pro, no SP, and installed it from a network share just fine. Tried to run update, got Windows Genuine Advantage (what a laugh), that couldn’t verify the legality of my totally legal copy and offered to sell me one. Or activate. Which, of course, it didn’t.

Tried to download just the SP3 to patch the XP locally, but meanwhile MSDN download services have stopped working for some f…ing reason. Couldn’t get it to work with any of my otherwise just fine XPs.

Erase. Write the Swedish XP Pro with SP3 to a real physical CD and installing from there, worked ok. Tried update. Windows Genuine Advantage. Could not verify I wasn’t a thief, assumed I was, told me to activate (even though I have a 60 day grace period on MSDN versions!), which, naturally, failed.

So I did what the thing recommends and started the phone activation procedure for the first time in my life. And, man, it’s gonna be the last one as well. Up pops a window with a phone number to call. Once there, you get to enter a code sequence using the phone keypad. Now, this is a little DECT phone with a little keypad and I’m asked to enter nine groups of six digits without fail. Yes, 54 digits… OMFG…

So I do. Guess what? My numbers can’t be verified. So I get a real human on the line. Thankfully I don’t have to enter everything again, the nice lady has the numbers already. Now she does some magic and hangs up, after which a robot reads out seven groups of six digits that I am to copy down then enter into the right fields.

For some inscrutable reason, this works.

Then I got a quiz, a “user satisfaction survey” which I couldn’t resist replying to. Questions like “Did you enjoy the activation procedure? (No!)”, “Was the customer representative nice? (Yes!)”, and more of that kind. The cutest one was: “How many times have you tried to activate, 1, 2-4, 5-10, more than 10? (5-10!)”, which shows a certain insight into how terrible this system is.

You’re supposed to answer with a 1 for terrible and a 9 for excellent, except they only say so right at the start and you’re expected to remember that. It’s entirely possible I got it backwards and thus expressed hate against the nice lady and unlimited adoration for the process itself. Too bad. Even though they’d never change the process because of customer dissatisfaction, the same may not be true for the representatives. (My apologies to the lady if I got it backwards.)

This entire process has cost me an hour. Now I need to do the same thing with a Norwegian copy and a Russian copy as well. And maybe even with Vista for the same three versions.

A few more validations like this, and I would have saved time by writing my own OS instead of using one from Microsoft. Productivity? Hah!

An exercise in restore

The worst just happened. The Windows XP instance I use for development, the one with VS 2008 on it, just bluescreened, then did disk repair, then went into a bluescreen cycle. Can’t break out of it even with safe boot. This is the one instance I have my development source in, and the one instance I updated to SP3. I can hear you snicker already. I’ll try to shoot a movie of the rebooting so you can enjoy it fully. Plus it may give me a chance to see what the error code actually is. Click the image for the movie.

If you watch really closely, you’ll see the error message “the windows logon process system process terminated unexpectedly” (you also see it in the screenshot above, of course). Using “the Google”, I found an article on MS Support that seems to describe what’s happening. I really don’t want to go through the recommended steps in that article and since I presumably have a pretty good backup, I’ll try my backup first.

Continue reading “An exercise in restore”

Vista has no respect for my work

Just for once, I opened up a Windows Vista (64 bit Ultimate) to run Ikea’s planning tool (I actually used the Swedish version of it). Ikea only makes it for Windows, but since I run Parallels and Fusion, I really don’t mind which OS the app is for. I run Vista more or less in its default state, especially since I haven’t spent any time on configuring it, and I don’t even know which nooks or crannies to work through.

So I downloaded and installed the Ikea planning tool. Admirably, Vista asked for the admin credentials to do that. Great. Then I started using the Ikea tool.

After a while, I leaned back thinking about what to do next and noticed in the task bar that “Windows Update” was running. It wasn’t signalling me in any way, but I idly clicked anyway and this is what I saw:

Vista reboot warning

CRIPES!!! It’s like in those movies when you hear a sweet voice over the PA system, saying “Countdown to self-destruct…. 60 seconds remaining….”. And there I was with a layout for my living room unsaved in the Ikea tool and I didn’t even know how to save, it being the first time I’ve used it. Trying to click “Postpone” or change the “Remind me in:” dropdown was futile. They’re disabled. A close button? No. Just a countdown.

I found the save and saved the file in Ikea’s app, took about ten seconds. Then intentionally left the Ikea app in the foreground just to see what kind of warning and choice I’d get from Vista when the countdown reached zero. Well, nothing. When the time expired, Vista rebooted without any information or choices being presented. This must be the most intentionally hostile action I’ve seen from an OS yet.

I run as a non-admin, of course, which may explain why Vista spits me in the face (it being in the Windows world a despicable thing to do, it seems), but still, can’t say I find it an admirable way of treating the user. It’s possible I could have terminated the update through the task manager, but since I’m running as non-admin, I doubt it.

Be warned. Be afraid. Either dig into the update settings and disable that crapola before it clobbers your work, or save every minute. Also, always keep an eye out for “Windows Update” in the taskbar. Never leave your computer unattended without saving everything first.

And this is progress?

Cleaner Windows

Windex spray bottleI’m getting more and more convinced that MS will start over with a Unix based OS (I’d call it Windex). If they’d include a virtualization system allowing them to run Windows apps on it, similar to what Fusion and Parallels are doing on the Mac, they would be able to transition, gradually replacing old Windows apps with new Windex apps. If they’d integrate the virtual Windows apps more tightly to the new OS than what Parallels or VMWare can do, they’d come out ahead.

It’s the only way out and it would put them ahead of Linux and OSX again. I’m sure they’re working on it. They’d be crazy not to.

PS: not an april fools joke, I mean it.

Mac Vista

Since I have both Parallels and Fusion running, I found it useful to try out Vista under Fusion. According to tests, Vista runs better under Fusion, while Parallels’ forte is XP. No, I haven’t verified that, I’m entirely happy assuming those tests are right.

Windows Vista is kinda pretty, even though I don’t see any aqua or aero effects, or whatever they’re called. (Here’s a full size view on how it looks while it is huffing and puffing its way through the initial 49 updates of the OS.)

But, even the Mac Pro I’m running now, with its 8 Gb of RAM is starting to page out when I’m running Vista. Admittedly, I’m running a few more things at the same time…

task bar, pretty full

… as you can see. Two XPs (1 Gb, resp 768 Mb) are running, Photoshop, Transit, the Fusion with Vista (1 Gb), Skype, Safari, OmniFocus, Mail, NeoOffice Writer, iTunes, Preview, Transit, and Activity monitor. As you can see on the activity pie chart, there’s just a gig of blue and nothing green to be seen. I guess the next move will be to fill’er up to 16 Gb of RAM, and if that’s not enough, I have to go to 32 Gb, which this machine is supposed to handle. I’m sooo spoiled…

Just like on OSX, I just now created a separate admin account and changed my regular account from admin status to “standard”. I’m very curious to see if it’s workable. While running as admin, I got a deluge of “Please approve this action” dialog boxes. Let’s see what happens if I’m not an admin and I try to install Open Office.

First, it blocked the download, warned me about the dangers of the internet, but it’s easy enough to approve it and proceed. Then it warned me about the installation program being unsigned, fair enough. Then it asked me for an admin logon to install the program (perfect!). And then the installation threw up an error box:

Failed Open Office installation

Did a quick Google and didn’t find anything about this error (“Wrapper.CreateFile failed with error 123”). Interestingly, after clicking “OK”, the installation proceeded, where I would have expected it to abort, rewarding me with:

Installation Completed dialog box

And, hey, it seems to work! Ok, so far so good under a limited user account. That is definitely good news.

Next little test, let’s open Task Manager:

Task manager

No problem, up it comes. Fine. Now let’s click “Resource Monitor”, which I know only admins can use:

Needs permission

Darn it, I’m bloody impressed! Instead of having to do that cumbersome “RunAs…” stuff, Vista does exactly what OSX does, asks for admin credentials (it even put in the right admin user name, which I rubbed out with a bit of yellow mud just above the password prompt). And up comes the resource monitor.

Phew, never thought I’d have to say I like this very limited first look at Vista after what I’ve heard about it. I think I’ll keep exploring it.

Now, let’s look at what Vista sees as the underlying machine, that is what Fusion pretends to be:

Basic info about computer

It sees a dual 64 bit processor and 1 Gb of RAM. Nice. If you look at the very bottom you see a new MS policy of automatically activating the OS, instead of letting the user do it. Normally I wouldn’t care, but if you’re running MSDN copies, you should be aware of this, since you often don’t want to waste activations on every installation you do. Vista isn’t going to wait for you to approve if I interpret that statement correctly. (I’ll wait and see if it goes ahead without asking or not after another three days, will keep you updated about it.)

So, what about the “Windows Experience Index”? It says “1.0” here, can’t be lower than that. Hm. Better check out the details:

Windows Experience details

Ah, now I see, the overall rating is equal to the lowest rating, which I got for gaming graphics. I have enabled “3D graphics” but I get no aero. I think Fusion doesn’t support Aero yet, but I couldn’t find anything on the web to confirm that, so I may be wrong. Apart from that, I find the above scores pretty impressive. Vista, at first blush, seems useable on this machine, not too sluggish, but then nothing is sluggish on this setup, really.