Memory Leaks

I think you mean BoundsChecker by Numega/Compuware (the same people who made SoftIce). And, yes, it is very expensive. And it doesn’t work all that well.

Something you might look into is a tool I use called “Visual Leak Detector”:

http://www.codeproject.com/tools/visualleakdetector.asp

For memory leaks it works like a charm. Other types of leaks are not detected. And, despite being in a section labeled “MFC/C++”, it works fine with plain ol’ C++ (meaning it’ll work with WTL).

GlowCode is supposedly a pretty good leak detection tool and is much cheaper than BoundsChecker but I don’t know how good it is.

Rational Purify is another product (by IBM – which should tell you how good it will be…that is, not very).

Detect HMODULE / HINSTANCE Within the Running Module

#if _MSC_VER >= 1300 // for VC 7.0
// from ATL 7.0 sources
#ifndef _delayimp_h
extern “C” IMAGE_DOS_HEADER __ImageBase;
#endif
#endif

HMODULE GetCurrentModule()
{
#if _MSC_VER < 1300 // earlier than .NET compiler (VC 6.0)

// Here’s a trick that will get you the handle of the module
// you’re running in without any a-priori knowledge:
// <a href="http://www.dotnet247.com/247reference/msgs/13/65259.aspx” title=”http://www.dotnet247.com/247reference/msgs/13/65259.aspx“>http://www.dotnet247.com/247reference/msgs/13/65259.aspx

MEMORY_BASIC_INFORMATION mbi;
static int dummy;
VirtualQuery( &dummy, &mbi, sizeof(mbi) );

return reinterpret_cast(mbi.AllocationBase);

#else // VC 7.0

// from ATL 7.0 sources

return reinterpret_cast(&__ImageBase);
#endif
}