Click here to Skip to main content
15,887,683 members
Articles / Multimedia / GDI

GDI Leak Detector - A special debugger to detect and locate GDI leaks

Rate me:
Please Sign up or sign in to vote.
2.79/5 (20 votes)
5 May 2014CPOL1 min read 223.4K   1.5K   31  
A special debugger to detect and locate GDI leaks, with source code.
/**********************************************************************
* 
* StackWalker.h
*
*
* History:
*  2005-07-27   v1    - First public release on http://www.codeproject.com/
*  (for additional changes see History in 'StackWalker.cpp'!
**********************************************************************
*  2005-08-25		-refined and refactored by chen deping for more
*					 convenient usage
**********************************************************************/
#pragma once

#include <windows.h>
#include <vector>

class StackWalkerInternal;
class CStackWalker
{
public:
	CStackWalker(LPCSTR szSymPath = NULL);
	~CStackWalker(void);
	BOOL GetCallstack(/*out*/std::vector<std::string>& callStacks, int skipFrameCount, int maxFrameCount=10);

private:
	enum { STACKWALK_MAX_NAMELEN = 512 }; // max name length for found symbols

	typedef struct CallstackEntry
	{
		DWORD64 offset;  // if 0, we have no valid entry
		CHAR moduleName[STACKWALK_MAX_NAMELEN];
		CHAR name[STACKWALK_MAX_NAMELEN];
		CHAR lineFileName[STACKWALK_MAX_NAMELEN];
		DWORD lineNumber;
	} CallstackEntry;

	void OnCallstackEntry(const CallstackEntry &entry, /*out*/std::string& result);
	void BuildSymPath(char* szSymPath, size_t nSymPathLen);
	BOOL LoadModulesSymbols();


	StackWalkerInternal *m_sw;
	HANDLE m_hProcess;
	DWORD m_dwProcessId;
	BOOL m_modulesLoaded;
	LPSTR m_szSymPath;

	friend StackWalkerInternal;
};

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
China China
I am a student from Shanghai Tongji University.

Comments and Discussions