CoCreateInstance Fails With “Class Not Registered”

Recently, I had a problem unique to my test machine. Attempting to call CoCreateInstance on a COM class provided by one of our DLLs resulted in HRESULT 0x80040154, which corresponds to “Class not registered”.

This was a mystery since regsvr32 appeared to properly register our DLL, and all the obvious registry keys were intact!

After a bit of web searching, I experimented with using CLSCTX_ALL instead of CLSCTX_INPROC_SERVER. Now, the call succeeded! But why, since this is a DLL and, therefore, should be considered an in-process COM server?

MSDN documentation states that CLSCTX_ALL is defined as the combination of CLSCTX_INPROC_SERVER, CLSCTX_INPROC_HANDLER, and CLSCTX_LOCAL_SERVER. I began substituting each one in turn and found that the key was CLSCTX_LOCAL_SERVER.

Stepping through the code in the debugger revealed that the instant the CoCreateInstance call was made, a new instance of dllhost.exe appeared in the process list. This explained why CLSCTX_INPROC_SERVER would fail, since strictly speaking, the DLL was being hosted in dllhost’s process space.

Ultimately, the problem turned out to be an artifact from an old COM+ experiment. There was a COM+ entry corresponding to our COM server in the Component Services panel (Control Panel | Administrative Tools | Component Services, under Component Services | Computers | My Computer | COM+ Applications). The COM+ entry dictated that the COM server be hosted by proxy by dllhost.exe. Deleting this COM+ entry and re-running regsvr32 fixed the problem.

Component Services panel in Administrative Tools

Posted in COM, Technology, Win32, Windows | Leave a comment

Stripping Vertical Whitespace Using tr

The Translate command, tr, is available on all Unix-y systems, including Cygwin. tr -d will delete the specified characters from a stream. Several handy escape sequences are provided for stripping newlines, carriage returns, and form-feeds:

  • \f – form feed
  • \n – new line
  • \r – return

Since tr is deleting characters, not strings, we can simply specify all of these in a single command:

cat input.txt | tr -d \r\n\f > output.txt

Another way to assemble this command:

tr -d \r\n\f < input.txt > output.txt

Posted in Linux, Scripting, Technology | Leave a comment

Snake

This story was a very interesting read.

Posted in Funny, Internet | Leave a comment

B.O.B. Yak Plus versus Ibex versus Panniers

Trailers versus Panniers

Based upon my online research, the trailer versus pannier debate will rage on forever. Panniers have the advantage of not requiring you to worry about a trailer. Trailers have the advantage of reducing your frontal area (and therefore wind drag), and in theory don’t require wheels nor frame as beefy as those needed to haul gear in panniers.

Both panniers and trailers can negatively affect handling. The degree to which they do, and the respective solutions, seem to vary tremendously by usage patterns. Overloading a trailer, particularly while putting most of the weight forward, is sure to cause handling trouble. Similarly, a heavy, low-slung rear pannier can badly disrupt handling.

Ultimately, there is no clear winner on any objective, universal, technical basis. It seems to be a personal decision, based upon one’s intended usage. Therefore, since I really don’t see any reason to own yet another bicycle solely for mid-weight touring, I will be buying a BOB trailer and attaching it to my carbon-framed, triple-chainring roadbike.

Now the question becomes, which trailer to purchase?

The Trailers

BOB makes two trailers, the Ibex and the Yak.

BOB Ibex trailer   BOB Yak trailer

The Ibex offers 3″ of adjustable, damped suspension travel, weighs 3.5 pounds more, is silver instead of black, and costs an extra $70.

Nomenclature

The only difference between the base and the “PLUS” models is the inclusion of the yellow, roll-top BOB bag (“DRY SAK” dry bag). The “28” versions are for 28″ wheels, 29″ mountain bikes, and 700cc road bikes with full-wrap fenders.

Specifications

This section lists the specifications for each, as reported on the BOB website. All differences are listed in bold.

Ibex:

  • MSRP: $369, $399 for PLUS model with “DRY SAK” bag.
  • Suspension: 3″, adjustable
  • Weight: 17 Lbs (7.7 kgs)
  • Capacity: 70 Lbs (32 kgs)
  • Wheel: 28 spoke, aluminum rim, cartridge bearings, 16 x 2.125″ tire
  • Cargo area: approx 25″ x 16″ x 18″ (64cm x 41cm x 46cm)
  • Included: quick release attachment system with spare attachment pin, bungee, flag, fender, reflectors
  • Color: gray?

Yak:

  • MSRP: $299, $329 for PLUS model with “DRY SAK” bag.
  • Suspension: none
  • Weight: 13.5 Lbs (6.1 kgs)
  • Capacity: 70 Lbs (32 kgs)
  • Wheel: 28 spoke, aluminum rim, cartridge bearings, 16 x 1.75″ tire
  • Cargo area: approx 25″ x 16″ x 18″ (64cm x 41cm x 46cm)
  • Included: quick release attachment system with spare attachment pin, spider bungee, flag, fender, reflectors
  • Color: black

Additional Information

This page provides far better photos of the Ibex than does their website. Also — again, unlike the website — it explains exactly how the shock absorber is “adjustable”. You can move the lower mounting point for different leverage, and you can increase the spring preload. Additionally, their Yak page shows exactly how the trailers mount to the bicycle.

Which to Choose?

The Internets

This guy used a BOB Ibex behind a hard-tail mountain bike on the Great Divide Route and has generally very positive things to say about it.

This thread compares the Yak to the Ibex. Several references are made to high-speed weaving and instability with the unsuspended Yak, which is said to be absent from the suspended Ibex, but some also say that this is simply due to improper loading.

My Decision

It sounds like the Ibex may reduce the chance of handling problems, particularly at high speeds. Since the downside is 3.5 pounds, and since I don’t believe that 3.5 pounds of rolling weight will be noticeable, I intend to purchase a BOB Ibex.

I will probably replace the 2.125″ Ibex tire with a 1.75″ slick, since I think rolling resistance is more likely to be felt than the absolute weight difference.

Followup

I bought the BOB Ibex and, sadly, decided that it sucks. I will be returning it next weekend. More details later.

Posted in Cycling | 2 Comments

SetThreadLocale and SetThreadUILanguage for Localization on Windows XP and Vista

Simple Localization

In classic Windows programming, the quickest way to handle localized resources is to put all languages into the same resource file, then use SetThreadLocale to tell Windows that it should return resources tagged with the specified language identifier. Subsequently, any attempt to load a resource by that thread will cause Windows to prefer resources corresponding to the specified language code.

Vista Complications

As of Windows Vista, calling SetThreadLocale will appear to work, but will have no effect. Your application will continue to use load resources using whatever language identifier is set as the user’s default.

Under Windows Vista, SetThreadUILanguage must be called instead of SetThreadLocale. This function is in Kernel32.dll. It appears in Vista, Windows 2008, and some versions of Windows XP. Under Windows XP, this function will not have the desired effect, and I have no idea what it does under Windows 2008.

Since the function isn’t available on all systems, you will probably want to use GetProcAddress to locate the function, and call it using a function pointer. However, since the function appears on Windows XP, but does not behave in the desired way, it’s important to only call it on Windows Vista.

Resource Storage

To use the SetThreadLocale or SetThreadUILanguage methods, the resource file must first be populated with all required languages. Each translated resource file should be appended to the .rc file, each one following an appropriate LANGUAGE statement and corresponding language identifier. (note that you could use separate .rc files and include them, in which case there are gotchas).

Is it Vista?

This function should reliably indicate whether the current OS is Windows Vista. I use GetVersionEx. Note that, even though we’re using an OSVERSIONINFOEX structure, we have to cast its pointer so that it appears as a OSVERSIONINFO pointer. No guarantee of future compatibility is implied:

bool IsOSVerWindowsVista()
{
    OSVERSIONINFOEX osver;
    ZeroMemory(&osver, sizeof(osver);
    osver.dwOSVersionInfoSize = sizeof(osver);

    if (!GetVersionEx((OSVERSIONINFO *)&osver))
        return false;

    // dwMajorVersion 6 and dwMinorVersion 0 means Vista or 2k8:
    if ( (osver.dwMajorVersion != 6) || (osver.dwMinorVersion != 0) )
        return false;

    // wProductType of NT_WORKSTATION means it's Vista:
    if (osver.wProductType != VER_NT_WORKSTATION)
        return false;

    return true;   
}

Calling SetThreadUILanguage Dynamically

The trickiest part of using GetProcAddress to dynamically call a function at run-time is getting the function pointer declaration correct. This type definition should work for SetThreadUILanguage:

typedef LANGID (WINAPI *FP_SetThreadUILanguage)(LANGID LangId);

Now, you have a function pointer type called FP_SetThreadUILanguage which can be used like any other type.

This function pointer can be used to dynamically call any function within a loaded module (DLL). SetThreadUILanguage lives inside Kernel32.dll. Since Kernel32.dll is required by all Win32 processes, we can simply use GetModuleHandle to find it, we don’t have to use LoadLibrary. A pointer to SetThreadUILanguage can therefore be retrieved like this (unnecessarily verbose code):

HMODULE hKernel32 = GetModuleHandle(_T("Kernel32.dll"));
FARPROC pFn = GetProcAddress(hKernel32, "SetThreadUILanguage");

FP_SetThreadUILanguage pSetThreadUILanguage = (FP_SetThreadUILanguage)pFn

The function can now be called through the function pointer variable:

LANGID langid = pSetThreadUILanguage(myLangId);

SetThreadUILanguage returns the LANGID which has been set. If the call was successful, it will return the same LANGID that was specified.

Constructing a Language Identifier

Use the MAKELANGID macro from Winnt.h, and supply LANG_Xxx constants from same. For example, Simplified Chinese would require:

DWORD dwSimplifiedChinese =
   MAKELANGID( LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED );

Non-Vista Platforms

On non-Vista platforms, SetThreadLocale can be used. Instead of a language identifier, it accepts a locale identifier. To generate the locale identifier, simply pass your language identifier to the MAKELCID macro, and supply SORT_DEFAULT as the second parameter:

SetThreadLocale(MAKELCID(myLangId, SORT_DEFAULT));

This example unconditionally sets the thread locale to Simplified Chinese in a single line of code:

SetThreadLocale(
   MAKELCID(
      MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED), 
      SORT_DEFAULT));

SetThreadLocale returns TRUE on success, FALSE on error.

Reference

Posted in Technology, Win32 | 1 Comment

Autohide Ubuntu Menu in MythTV

When running MythTV under Ubuntu, the top menu (panel) may appear over MythTV’s output. The panel can be set to auto-hide, but even when hidden, several pixels will be displayed to remind you of its presence. Luckily, the number of pixels shown can be customized.

  1. Run gconf-editor.
  2. Select apps | panel | toplevels | top_panel_screen0.
  3. Check auto_hide, if you haven’t already turned auto-hiding on.
  4. Set auto_hide_size to 0 (or whatever number of pixels you want to be displayed in “hidden” mode).
Posted in Linux, Technology | Leave a comment

Hauppauge HVR-1800 with MythTV

The Hauppauge WinTV HVR-1800 is a PCI-Express card which has two tuners: one for ATSC/QAM digital video, and one for NTSC analog video. According to the MythTV wiki, only the digital video tuner is currently supported.

Hauppauge’s Windows driver, which contains the proper firmware, plus a shell script to perform the extraction, can be found on Steven Toth’s site (last updated Jan 2008).

Posted in Linux, Technology | Leave a comment

Underlining Characters in a ToolTip

My product, a toolbar for Outlook Express, uses tooltips to display keyboard shortcuts. For some localization work, I needed to display an underlined character within a tooltip.

The only hint I could find was a reference to .Net tooltips.

Apparently, in both .Net and Win32 tooltips, a single ampersand will be stripped, a double ampersand will cause the next character to be underlined, and three ampersands will display a single ampersand.

Input     Displayed
&B B
&&B B
&&&B &B

Note that this will be affected if the TTS_NOPREFIX flag is set, which prevents ampersands from being stripped.

Posted in Technology, Win32 | Leave a comment

Tartine Bakery in San Francisco

B, T, and I stopped at Tartine Bakery after “Beer Croquet” (which, due to a lack of a croquet set, became merely “Beer” in Dolores Park). I had the bread pudding and a mocha, and both were excellent. The bread pudding had a healthy dose of very tasty fruit in it, and the mocha was extremely well made, not too sweet.

However, as a single eater, I should have gotten the cup of bread pudding rather than the bowl. Two hours of beer plus a huge bowl of bread and sugar equals an amazing stomach ache…


View Larger Map

Posted in Food | Leave a comment

Worst Spam Ever

It’s not even really spam. I assume it’s an attempt to validate random email addresses by analyzing bounces.

Worst Spam Ever

Posted in Funny, Internet | Leave a comment