Archive for the 'Software development' category

Create a multi-lingual / multi-language MSI using WiX and custom build scripts

March 13, 2010 6:53 pm

Some people might find this useful, so I thought I’d write it up. If you want to create a multi-language MSI (Windows Installer package) that works without a bootstrapper executable, this is one possible way to do it. It relies on an undocumented feature of Windows Installer, so proceed with caution/at your own risk. Testing your final output is a must.

Anyway, according to this article at installsite.org, you can embed transforms into an MSI in a way so that Windows Installer will automatically apply them according to the system language when your MSI is loaded. This is the undocumented feature. If your MSI is simple enough that you don’t need dialog boxes/UI, but you just blaze through a default install, yet you want the few messages that show up by default to be localized, what I’m about to describe might be enough for you.

Here’s what you need: WiX (Windows Installer XML toolset), MsiTran.exe and some sample MSI scripts from the Windows SDK, and finally some custom-written scripts to glue the whole thing together.

I’ll assume you already have WiX installed (possibly in conjunction with Visual Studio), and that you have a simple, single-language WiX project handy.

You can get the Windows SDK from Microsoft as an ISO image (this one is for Windows 7). You can then mount this image using Magic Disc, Daemon Tools Lite or some other ISO-peeking utility. If you don’t want to install the entire SDK just to get the MsiTran.exe and MSI script samples, open the ISO up using your tool of choice and find the folder Setup.

To install just the tools package that will give you the MsiTran.exe, run WinSDKTools\WinSDKTools_x86.msi. MsiTran.exe will be found in %ProgramFiles%\Microsoft SDKs\Windows\v7.0\Bin after this. I suggest copying this file to your WiX installer project folder.

To get the script samples, run the MSI WinSDKSamples\WinSDKSamples_x86.msi. Once you’ve done this, you’ll find the sample scripts in %ProgramFiles%\Microsoft SDKs\Windows\v7.0\Samples\SysMgmt\Msi\scripts. Out of all these scripts you only need WiSubStg.vbs and WiLangId.vbs. I suggest copying them to your WiX installer project folder.

You should know ahead of building the original WiX project which languages and how many languages you’ll end up needing. Your original installer needs to list all of these in a comma separated list in the Summary Stream (and the list can’t contain 0). In WiX that looks like this:

<Package
  Compressed="yes"
  Description="My Installer"
  InstallerVersion="200"
  Comments="My Software Installer"
  Languages="1033,1031,1028,2052,1030,1043,1035,1036,1040,1041,1042,1044,1046,1034,1053,1049,1055,1045,2070"
/>

Once you’ve built the single language MSI using WiX, you run a script for each language you need your MSI localized in that does the following:

  • Copy the original MSI to a new file
  • Modify the newly copied MSI so it contains a different ProductLanguage using WiLangId.vbs
  • Create a transform that captures the difference between the two MSIs using MSITran.exe
  • Embed the transform in the final master installer using WiSubStg.vbs

Here’s the script that does it (I call this CreateEmbedLangTransform.cmd):

set MsiName=%1
set lang=%2
set langcode=%3
copy %MsiName%.msi %MsiName%_%lang%.msi
cscript WiLangId.vbs %MsiName%_%lang%.msi Product %langcode% > CreateLangTransform_%lang%.txt
MsiTran.exe -g %MsiName%.msi %MsiName%_%lang%.msi %lang%.mst >> CreateLangTransform_%lang%.txt
cscript wisubstg.vbs FinalMasterInstaller\%MsiName%.msi %lang%.mst %langcode% >> CreateLangTransform_%lang%.txt
cscript wisubstg.vbs FinalMasterInstaller\%MsiName%.msi >> CreateLangTransform_%lang%.txt

All you have to do as a post-build step (either in Visual Studio or as part of your build engine of choice) is call this script once for each language you’re interested in (I call this CreateLocalizedInstallerAllLanguages.cmd):

if not exist FinalMasterInstaller md FinalMasterInstaller
copy MyInstaller.msi FinalMasterInstaller
call CreateEmbedLangTransform.cmd MyInstaller da 1030
call CreateEmbedLangTransform.cmd MyInstaller de 1031
call CreateEmbedLangTransform.cmd MyInstaller es 1034
call CreateEmbedLangTransform.cmd MyInstaller fi 1035
call CreateEmbedLangTransform.cmd MyInstaller fr 1036
call CreateEmbedLangTransform.cmd MyInstaller it 1040
call CreateEmbedLangTransform.cmd MyInstaller jp 1041
call CreateEmbedLangTransform.cmd MyInstaller ko 1042
call CreateEmbedLangTransform.cmd MyInstaller nl 1043
call CreateEmbedLangTransform.cmd MyInstaller no 1044
call CreateEmbedLangTransform.cmd MyInstaller pt_br 1046
call CreateEmbedLangTransform.cmd MyInstaller sv 1053
call CreateEmbedLangTransform.cmd MyInstaller zh_cn 2052
call CreateEmbedLangTransform.cmd MyInstaller zh_tw 1028
call CreateEmbedLangTransform.cmd MyInstaller ru 1049
call CreateEmbedLangTransform.cmd MyInstaller tr 1055
call CreateEmbedLangTransform.cmd MyInstaller pl 1045
call CreateEmbedLangTransform.cmd MyInstaller pt_pt 2070

You’ll need to look up additional language codes in Microsoft’s documentation if you need more than the ones listed above.

Note that I’ve modified the scripts above from the ones I’m actually using to make them a little more generic, and I haven’t tested every aspect of them, but they give you the gist of it.

Here are the script files zipped up.

HP TouchSmart SDK 3.0 – Giveaways at PDC 09

November 17, 2009 9:00 am

To mark the release of the TouchSmart 3.0 SDK, HP has a goodie to give away at the Microsoft PDC 09: A super-slim 2 GB USB memory stick (embedded in a hard-plastic business card with a nice imprint). It contains the new SDK and a few documents about a software development partner program HP is starting.

If you see me at PDC, say hi, and I may be able to hand you one of these puppies. I only have a limited supply, though. 15 to be precise.

Check out the pictures:

IMG_3135

Front of the card

 

IMG_3136

Back of the card

 

IMG_3137

Back of the card with USB memory stick flipped open/out

 

IMG_3138 

Front of the card with USB memory stick flipped open/out

New SDK for HP TouchSmart software development – out now!

November 16, 2009 8:30 am

TS3SDK01

Today HP is announcing a new Software Development Kit for helping you write apps that play well in the HP TouchSmart “shell” environment. The new SDK still contains the general guidelines that outline both what makes a good app that’s optimized for touch interaction and the general rules you have to play by in order to “fit” into the HP TouchSmart shell.

But this time around there’s more: For the first time there is also documentation for a WPF library that you can use to more quickly write an app that heeds all of the rules that need to be followed. This library has actually existed for a few releases already, but it was not documented until now (for HP TouchSmart 3.0).

There are also two sample applications. One that demonstrates the basics of the WPF library (and that shows you what the shell does to the apps on a pretty detailed level – it’s great for seeing what registered messages are sent to the app, how the app gets sized, etc.) and one that’s a little game. To round out things, there’s some skeleton sample app code as well, so you can get started quickly with your app idea.

Here are a few screenshots of the two sample apps:

TS3SDK03

“Hello world” Wide-interactive tile

 

TS3SDK08

“Hello world” Large tile

 

TS3SDK10

Notification with CircleX icon

 

TS3SDK11

Notification with CircleCheck icon

 

TS3SDK02 

“Hello Mole” Wide-interactive tile

 

The documentation is provided in two forms: PDF for easy printing and reading offline as well as in Windows Help format for easy searching and looking at class library details.

You’ll notice that most of this only applies to WPF development. If you’re not using WPF yet (why aren’t you? – it’s a great platform), the general guidelines still apply and work. The shell is actually technology agnostic, since all it cares about, really, is the window (handle) your app produces. As long as your technology stack produces a Win32 window, you can “play”. The essence of that is something I’ve talked about before.

So where can you get this newfangled contraption? Head right over to http://www.touchsmartdevzone.com/download/file/2074-27 to start downloading. There’s still a license agreement in the installer (to make the lawyers happy), but I believe you can now download the thing without having to consent to the agreement first.

HP TouchSmart application development in a nutshell

September 24, 2009 5:09 pm

There is a document available for download (wrapped in an MSI to keep the HP lawyers happy) that describes all the nitty-gritty details of how to create an app that “fits” into the HP TouchSmart software environment. But some people might enjoy just a quick introduction to what it takes to get an application to show up in the HP TouchSmart software. So here’s my attempt at providing just the essentials in a bulleted list:

  • Create a Windows app using any technology you please (C++, MFC, VB, WPF, Flash, Air, whatever)
  • Do not use DirectX exclusive mode
  • Make sure the app produces one Win32 window (and only one window) and does this quickly
  • Make sure the window has no “chrome” whatsoever (no borders, resize grips, close/minimize/maximize buttons, system menu, etc.)
  • Make sure the window can still be resized by WM_SIZE and moved by WM_MOVE messages (and make sure it does so very responsively)
  • Make sure the window content is touch friendly

That’s it. If you know how to produce a program that does the above, you’re all set. No need to learn any interfaces, new programming models, technologies, nothing. I’ve actually had partial success at getting apps designed for Windows 1.0 to run inside the HP TouchSmart environment.

Now, if you want to improve on things, here are some more things you could do:

  • Make sure you have a black background for your window
  • Support the three “layouts”/sizes that HP TouchSmart uses as the user interacts with the UI (small, medium, large)
  • Take into account that the user can only interact with your window in large layout/size
  • Present something useful/informative in small and medium layout/size
  • Provide a beautiful, large icon

And to make it really great:

  • Use the notification mechanism that the environment provides (if your app needs to notify the user of anything)
  • Use the mechanism for launching IE that the environment provides (if your app needs to put the user in a full web browser experience)

Finally, use the RegisterSmartCenterApp.exe registration mechanism (described in the document linked to above) in the package you deliver for installing your app. You need to do that so program you’ve developed can be integrated into the HP TouchSmart UI.

If you’ve climbed the WPF cliff, the latest version of the HP TouchSmart software (2.8) includes a library that you can use for even closer integration. Leave a comment if you’d like more information about that. I don’t consider that part of the “nutshell”, since it ends up binding you to a specific technology stack.

Why are you not a member of the ACCU?

August 6, 2009 9:36 am

ACCU Home page

You may never have heard of ACCU, the Association of C and C++ Users as it was originally called. It is a volunteer organization, consisting of programmers who care about programming. The ACCU publishes two magazines, both devoted to raising the standards of programming everywhere: C Vu and Overload. On top of that they organize a conference every year, where some of the top names in C/C++ programming (and many other software development fields) come to speak and mingle with programmers from all around the globe.

I was introduced to the ACCU several years ago, when I first came to Silicon Valley, and still renew my membership every year, even though I don’t attend the local ACCU-USA events anymore. Yes, there is a local “chapter” of the ACCU in Silicon Valley, and they have monthly events that you can attend for free. I had the good fortune of hearing Bjarne Stroustrup speak once (plus going to dinner with him and the rest of the attendees afterwards, and even getting to exchange a few words with him in private.)

C Vu Volume 21 Issue 3 Cover     image

At one time I also co-hosted an event for the ACCU, and I think it is this personal connection that has kept me going as a member, even though I’ve not been much directly involved since. What keeps me hanging on now are the two excellent journals, which are largely ad-free and contain almost nothing but passionately written articles and code samples, demonstrating how to become a better programmer.

If this is something you strive for, I highly recommend checking out the ACCU and encourage you to become a member. Even if you live in the United States or elsewhere outside the UK.

Windows Vista Ultimate customers get the shaft – again

June 26, 2009 8:04 pm

A lot has been written about how Windows Vista Ultimate was a major disappointment. First it was billed as the version that would “keep on giving” in the form of Ultimate Extras – cool new features that would be exclusive to Ultimate customers. When those extras finally materialized most people were underwhelmed. The extras were mostly Language Packs, DreamScene (with a few content packs) and a game or two. And for that, people paid a hefty premium over the Home Premium edition.

Now Microsoft has published special early upgrade pricing to entice people to rush out and get Windows 7 “while supplies last”. And they’re at it again. Guess what the upgrade price for Windows 7 Ultimate is:

WindowClipping

Yup.

$219.99!

Sorry to shout there. At least this time there’s no promise of “Extras”. Only BitLocker and Language Packs (in addition to the Professional features). Not sure that’s worth $120 over the Professional Upgrade or $170 over Home Premium (even considering XP mode.)

Oh, and you can’t do an edition “downgrade” from Vista to 7. You can buy the upgrade package, but you’ll have to use it to do a “custom install” (i.e. clean install) and then reinstall all your programs and data. Despite that inconvenience, I’ll go for the Home Premium upgrade, thank you very much. I’m done being an Ultimate customer. Or is that Ultimate fool?

(And just for the record, Windows 7 is a fantastic product in my opinion. I hope Paul Thurrott is right when he says it may be the next Windows NT. Unfortunately he also seems to be right about how Microsoft can mess things up with their pricing)

MSI custom action type 50 / 51 failures? Beware of quotes.

April 25, 2009 10:37 pm

This one cost me a lot of wasted time recently. I was authoring an MSI package using the otherwise excellent open source WiX package from Microsoft and kept getting 1721 errors when a custom action was supposed to run. If you get this problem, let me attempt to save you a bit of time.

If you author a type 50 custom action that runs an exe on the system, based on a registry app search in combination with a type 51 action for example, make sure you don’t put quotes around the property that defines the exe path in the type 51 custom action. In other words, don’t author it as “EXEPROPERTY”, but just EXEPROPERTY.

You may think you need the quotes if your exe path has a space in it somewhere, but you don’t.

Now, if your type 50 action uses an ExeCommand and part of that has spaces in it, that usually needs to be quoted.

Looks inconsistent to me, but I guess the ways of the Windows Installer are inscrutable and mystical at times.

My type 50 action actually ended up as 1138 or something because of deferred execution and no impersonation, but basically the same idea applies.

HP TouchSmart development on .NET Rocks!

December 2, 2008 11:54 pm

Check out the interview with some of the HP TouchSmart folks on .NET Rocks! It just went live earlier today.

http://www.dotnetrocks.com/default.aspx?showNum=399

The parts for developers are mostly in the first 15 minutes. I have some PDF slides that might illustrate things for people who are just looking for a quick visual and not a whole lot of depth. If you’re interested, let me know and I’ll post them here.

WIC metadata in .NET: Getting around "Property cannot be found" / System.ArgumentException /"Exception from HRESULT: 0×88982F40"

November 16, 2008 9:39 pm

Here’s a bit of an obscure error message I’ve run into while working with WIC (Windows Imaging Component) on .NET/WPF, trying to write XMP metadata into an image:

image

 

 

 

 

 

 

 

 

 

 

So far, a search on Google has yielded few usable results. I hope this post will change that, yielding at least one useful thing.

The Exception message tells you that you’re trying to write data to a property that doesn’t exist in the file. Microsoft has a tool called WICExplorer that can show you the metadata like this:

WIC_Before

The above shows an image in WICExplorer directly after coming off of my digital camera. Notice that there is no “XMP Reader” node, which would represent XMP metadata. So if you want to put new XMP metadata into the picture, you need to know two things: how to create a new metadata node and what the correct syntax is for doing so.

What helped me figure those two things out were these pages:

http://social.msdn.microsoft.com/forums/en-US/wpf/thread/8f297b11-99ba-459c-b085-1ff3ae526487/

http://msdn.microsoft.com/en-us/library/bb643802.aspx

The first one showed how one can create new metadata objects using WIC, the second showed the needed syntax for some of the queries.

So here’s an example of how to create XMP metadata in an image that doesn’t have XMP metadata embedded yet:

   1: string file = "C:\Temp\IMG_1687.JPG";
   2: BitmapCreateOptions createOptions = BitmapCreateOptions.PreservePixelFormat | BitmapCreateOptions.IgnoreColorProfile;
   3: Stream originalFile = File.Open(file, FileMode.Open, FileAccess.ReadWrite)
   4: BitmapDecoder original = BitmapDecoder.Create(originalFile, createOptions, BitmapCacheOption.None);
   5: BitmapMetadata metadata = original.Frames[0].Metadata.Clone() as BitmapMetadata;
   6:  
   7: string q = "/xmp/exif:UserComment/x-default";
   8: if (metadata.ContainsQuery(q))
   9: {
  10:   metadata.SetQuery(q, comment);
  11: }
  12: else
  13: {
  14:   metadata.SetQuery("/xmp/exif:UserComment", new BitmapMetadata("xmpalt"));
  15:   metadata.SetQuery(q, comment);
  16: }

The keys are in line 7, where the initial metadata query is shown and in line 8, where the code tests if the metadata is already present. If not, line 14 shows how to create a new XMP metadata node, which then gets populated in line 15. The writing of the data can be done using a JpegBitmapEncoder according to Robert Wlodarczyk’s blog post (without the InPlaceBitmapMetadataWriter piece.)

After running code like this, you’ll now have the metadata in the file, as shown by this WICExplorer screenshot (I added “App0 Reader” metadata to this image as well):

WIC_After

Hopefully this is useful to some folks out there. Enjoy!

HP TouchSmart / badges at PDC 08

October 24, 2008 10:44 pm

You’ll see a lot of the HP TouchSmart PC at the Microsoft PDC 2008 starting on Monday. Not only physically, but also as it relates to the software. Can’t say any more than that right now.

We’ll have two of the HP TouchSmart software developers attending, so if you see them, don’t be shy. Please come and say "hi".

If you do, we’ll have some stuff to share that should make people who have commented on some of my previous posts a little happier, I think. Again, I can’t say any more than that now.

Oh, and we’ll have PDC badges to hand out. Here’s a sample:

ATouchDifferent

We have five different ones, but only a limited supply.

Oh, and we may do an OpenSpace session, although I’m not sure we’d be in "compliance" with the rules. Let’s see.

I’m definitely looking forward to PDC 08!

I’ll be wearing my geek tie (recently "upgraded", too). Hope to see you there!