HeapCheck:
1. Disclaimer/Authors
2. Features
3. Introduction
4. Usage
5. Configuration
6. Debugging tools
7. UNIX gurus
8. Stack techniques
9. Known bugs
10. Contact me
11. Get 1.34
12. Get 1.2 (stable)
13. PDF manual
14. WinCE patch for 1.2
 
Back to HomePage
  Next Previous

4. Usage

You can easily use HeapCheck in your own programs in three easy steps:

  1. In the source files where you want the checks to take place, include the swaps.h header file. Make sure that it is the first include file you are using, after the system and RTL include files, e.g.
            #include <xxx.h>
            #include <yyy.h>
            ...
            #include "swaps.h"
            #include "myfile1.h"
            #include "myfile2.h"
            ...
    
    This file #defines the calls to heap-related functions in your code to calls in the library. It also provides the prototypes for the new allocation and deletion operators.
  2. If your code is in C only, add HeapCheck.c in the project, or
    If your code is in C++, add HeapCheck.c and CplusCheck.cpp in the project.
  3. Add imagehlp.lib in your link libraries.

That's it. Your code will be automatically checked for heap errors. To get correct file/line information, make sure you are using the correct versions of the debugging libraries (the Windows 2000 ones). I used dbghelp.dll version 5.0.2195.1, and imagehlp.dll version 5.0.2195.1. Maybe SymGetLineFromAddr() works with other combinations, but I used these DLLs successfully under both NT 4.0sp6 and Windows 2000.

By default, range checks will be done for post-block accesses.

After checking that everything works OK in this setup, modify your project so that PRE_CHECK is defined, or even edit swaps.h and define it on top:

                #define PRE_CHECK
Recompile everything, and this way, pre-block checking will take place.

HeapCheck messages appear on the Debugging Output of Visual C++. If you are running the program outside the IDE, use DebugView to see them (get it from www.sysinternals.com, an awesome site for programming utilities by the way).

If you program with MFC, make sure you use it in the form of a dynamic DLL (Project - Settings - General - Microsoft Foundation Classes - Use MFC in a Shared DLL) . Otherwise, you 'll get link problems, since MFC defines a global operator new, just as HeapCheck. If you use it in the form of a DLL, MFC sticks to its own operator new, while your code calls HeapCheck's.

When you have debugged your program, just recompile in Release mode. The debugging checks will melt away automatically.


Next Previous