Web site and Blog updated

I’ve updated my web site with all the articles I’ve written/updated in the gap since my last site-update and also added a Free Tools section. The Articles page is now pretty big – so maybe I should break it down into separate sections – oh well, next update I guess:-) Anyway, when you are free, please check out www.voidnish.com.

With Jambo’s live help, I’ve also upgraded my blog’s WordPress version to and it’s got some new features as you may have observed and it’s also pretty good at stopping comment spam. I’ve also applied a new theme, so if you were used to the old look & feel, it may take you a while to get used to the new one. I’ve optimized my blog for viewing at 1024 x 768 resolution, so any 14-inchers out there may have a little bit of a problem.

There’s a bug too which I haven’t been able to solve yet. Initially I thought it was a bug in Jambo’s colorizer plugin and so did he, but even after I disabled the colorizer, the bug persisted. It’s a rather annoying bug too, it changes all occurences of ” to \” – pretty crazy considering I’ve got lots of code snippets containing “s. Oh well, hopefully it should be an easy fix.

Casting to a specific function overload

See these two overloads of a function F :-

void F()
    cout << "F()" << endl;

void F(int i = 10)
    cout << "F(int) " << i << endl;

Now if you attempt to call the function as F() you’ll get a compiler error.

F(); <- C2668: 'F' : ambiguous call to overloaded function

The right way to do this would be :-

((void (*)(void))F)();
((void (*)(int = 10))F)();

Looks beautiful, doesn’t it? C++ syntax is truly the most beautiful among all programming languages!

0x27F3 days!

It’s now 0x27F3 days since I entered this world – wow, that sounds like such a long time into the past, though my grandma says she remembers it as if it was just yesterday. Grandmas always do that, they say that they remember things very clearly when they know you weren’t born then or were just a baby and thus can’t contradict them on anything they might have mis-remembered. By the way, what’s really frightening when you grow older is that it gets harder and harder to find Scotch whiskey that’s older than you are.😳

GetProcessImageFileName/QueryDosDevice trivia

If you’ve ever used GetProcessImageFileName, you’d have been a little stunned to see filenames like \Device\HarddiskVolume1\Program Files\Abc.exe – though when you think of it, it’s not all that surprising, because these are the real paths as far as the OS is concerned, all that kiddy-type C-drive, D-drive usage is mere eye-candy for us non-kernel-programmer types. Anyway, you can’t get a DOS drive name directly from this sort of path, instead you’d have to use QueryDosDevice with each drive letter from A to Z and if what it returns matches the path you have, you’ve got your drive letter. Here’s a little copy/paste-able function you can use :-

    lpDevicePath - should be something like "\Device\HarddiskVolume1",
        "\Device\Floppy0" or "\Device\CdRom0"
TCHAR GetDriveLetter(LPCTSTR lpDevicePath)
    TCHAR d = _T('A');
    while(d < = _T('Z'))
        TCHAR szDeviceName[3] = {d,_T(':'),_T('\0')};
        TCHAR szTarget[512] = {0};
        if(QueryDosDevice(szDeviceName, szTarget, 511) != 0)
            if(_tcscmp(lpDevicePath, szTarget) == 0)
                return d;
    return NULL;

GetProcAddress in Unicode builds

If you have code like this :-


It won’t compile when UNICODE is defined.

This is so because there are no separate GetProcAddressW/GetProcAddressA functions. The second argument to GetProcAddress is an LPCSTR (const char*), because exported names in Win32 modules are stored as ANSI strings. The right way to write the above line would be :-


I can’t remember right now if there are other commonly used API functions that depict similar behavior.

IsAppThemed and IsThemeActive just don't work

I was most annoyed when I found that IsAppThemed and IsThemeActive do not work as expected. Instead of returning the themed status of the running application, both functions return the themed status of the system (pretty much useless for my specific requirement). After some googling, I found a posting from a fellow-MVP, Jeff Partch, who suggested calling GetModuleHandle on comctl32.dll and comparing this module handle with the handle returned by calling GetClassLongPtr on a known control handle with the GCLP_HMODULE flag. While I didn’t actually try that out, I thought it’d be easier to call DllGetVersion on comctl32.dll and check if the version is 6 or greater.

I ended up writing my IsThemed function which I have sumitted to The Code Project. Here’s the article link (with screen shots and history) :-

How to accurately detect if an application is theme-enabled?

And here’s the full function listing :-

(You’ll be wondering why I profusely used LoadLibrary/GetProcAddress. Well, I wanted to support VC++ 6 and the code now compiles on the default installation of VC++ 6, without the Platform SDK)


#pragma once

#include "stdafx.h"
#include <Shlwapi.h>

BOOL IsThemed()
    BOOL ret = FALSE;
    OSVERSIONINFO ovi = {0};
    ovi.dwOSVersionInfoSize = sizeof ovi;
    if(ovi.dwMajorVersion==5 && ovi.dwMinorVersion==1)
        //Windows XP detected
        typedef BOOL WINAPI ISAPPTHEMED();
        HMODULE hMod = LoadLibrary(_T("uxtheme.dll"));
            pISAPPTHEMED = reinterpret_cast<ISAPPTHEMED*>(
            pISTHEMEACTIVE = reinterpret_cast<ISTHEMEACTIVE*>(
                if(pISAPPTHEMED() && pISTHEMEACTIVE())

                    HMODULE hModComCtl = LoadLibrary(_T("comctl32.dll"));
                        pDLLGETVERSION = reinterpret_cast<DLLGETVERSION*>(
                            DLLVERSIONINFO dvi = {0};
                            dvi.cbSize = sizeof dvi;
                            if(pDLLGETVERSION(&dvi) == NOERROR )
                                ret = dvi.dwMajorVersion >= 6;
    return ret;

The guy who never combed his hair

I remember how, back during my college days, a lady-classmate referred to me as a guy who never combs his hair, never wears a watch and whose idea of formal wear is a wrinkled t-shirt and worn-out jeans. This might possibly be alarming to some of you, but she was dead accurate. It’s now close to 15 years since I’ve worn a watch and for time-keeping purposes I’ve depended on my cell phone during the last 5 years. It’s not that I have anything against wearing a watch, it’s just that I had some kind of rash on my wrists and was advised by the doc to temporarily avoid wearing a watch and after keeping off wearing watches for a while, I kinda started liking it. I don’t remember the last time I voluntarily combed my hair (some of my female relations have uncouthly forced their hair combing felonies on my poor hair), but it must be more than a decade now since I quit trying to keep my hair all combed and ready. T-shirts are still my favorite apparel, specially if they have any Microsoft-specific logos on them, though I don’t wear denim trousers anymore. Since I am approaching middle-age I have shifted to wrinkle-free cotton trousers. Well, if my critic classmate was asked to comment on her statement of yore, she’d probably look at me now and say she stands to her statement, though technically she’d be wrong cause of my having abandoned jeans for cotton trousers. *sigh* I guess I am not ever going to win a fashion contest, but then when has that ever deterred me from dressing as comfortably as I felt like? :nerd: