NULL hInstance Considered Harmful
On a couple of occasions, I've converted large Windows applications from EXEs to DLLs which are loaded by stub EXEs. There are several reasons you might want to do this, and for the most part it's surprisingly easy. Most Windows code doesn't know or care if it's running in a DLL or EXE, as long as it has the right instance handle for any functions that load resources or the like.
There were a few Windows functions that gave us grief, though. These are the functions that accept a NULL
hInstance to mean the current process. I used to think this was a nice convenience, but all the code that used a NULL
hInstance had to be converted to take an explicit
I searched for the functions that came to mind and fixed them:
But I forgot about an entire group of functions and had to find them the hard way, through some tedious debugging:
Are there more functions like this?