Click here to Skip to main content
15,896,497 members
Articles / Programming Languages / Visual Basic

Easy Detection of Memory Leaks

Rate me:
Please Sign up or sign in to vote.
4.73/5 (25 votes)
4 Aug 20058 min read 186.8K   8.6K   122  
Describes a tool for easy detection of memory leaks.
//////////////////////////////////////////////////////////
// Basic log writer implementation
//
// migo (2005)
//////////////////////////////////////////////////////////

#include "LogWriter.h"

#define PULONG_PTR LPVOID
#define ULONG_PTR LPVOID
#include "dbghelp.h"



/////////////////////////////////////////////////////////////
// WriteToLog
/////////////////////////////////////////////////////////////
BOOL WriteToLog( HANDLE hF, LPCTSTR strFormat, ... )
{
	TCHAR buf[2048];
	va_list args;
	va_start( args, strFormat );
	_vstprintf( buf, strFormat, args );
	va_end( args );

	
	DWORD dwWritten;
	return ::WriteFile( hF, buf, _tcslen(buf), &dwWritten, NULL );
}


/////////////////////////////////////////////////////////////
// InitLogFile
/////////////////////////////////////////////////////////////
HANDLE InitLogFile( LPCTSTR strReportFileName )
{
	SymInitialize( ::GetCurrentProcess(), NULL, TRUE );

	HANDLE hF;
	hF = ::CreateFile( strReportFileName, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );

	if( INVALID_HANDLE_VALUE == hF )
		return hF;

	WriteToLog( hF, "Created by MemoryHooks" ENDL
					"----------------------" ENDL );

	return hF;
}


/////////////////////////////////////////////////////////////
// CloseLogFile
/////////////////////////////////////////////////////////////
BOOL CloseLogFile( HANDLE hF )
{
	SymCleanup( ::GetCurrentProcess() );

	return ::CloseHandle(hF);
}

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Israel Israel
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions