Click here to Skip to main content
15,896,269 members
Articles / Programming Languages / C++

Customized Visual Studio .NET package: your fully integrated document window inside the IDE

Rate me:
Please Sign up or sign in to vote.
4.72/5 (20 votes)
20 Dec 200313 min read 63.9K   1.1K   39  
Create a fully integrated document window inside the Visual Studio IDE.
#pragma once


#define DECL_SPY_OBJ(NAME)	namespace NAME##NS { void AttachSpy( void* pObj ); }


#define START_IMPL_SPY(NAME,NUM_METHODS)	\
namespace NAME##NS {		\
	typedef void (*TFn_StubFunction)(void);	\
	static TFn_StubFunction  _StubVTbl[NUM_METHODS];	\
	static TFn_StubFunction  _StubVTblLocal[NUM_METHODS+10];	\


#define SPY_STUB_(NUM,MSG)					\
void __declspec(naked) _SpyStub##NUM(void)		\
{										\
	__asm{ push esi }					\
	OutputDebugString( "=> " MSG "-" #NUM "-\n" );		\
	__asm{ pop esi }					\
	__asm{ lea eax, _StubVTbl }			\
	__asm{ mov eax, [eax+NUM*4] }		\
	__asm{ jmp eax }					\
}										\


#define SPY_STUB_SILENT(NUM)	\
void __declspec(naked) _SpyStub##NUM(void)		\
{										\
	__asm{ push esi }					\
	__asm{ pop esi }					\
	__asm{ lea eax, _StubVTbl }			\
	__asm{ mov eax, [eax+NUM*4] }		\
	__asm{ jmp eax }					\
}										\


#define SPY_STUB(NUM)		SPY_STUB_(NUM,"Stub")


#define SPY_START_VTBL(NUM_METHODS)	\
void AttachSpy(void* pInterface)					\
{												\
	TFn_StubFunction** pOrigVTable = (TFn_StubFunction**)pInterface;	\
	CopyMemory( _StubVTbl, (*pOrigVTable), sizeof(void*)*NUM_METHODS );	\
	CopyMemory( _StubVTblLocal, (*pOrigVTable), sizeof(void*)*(NUM_METHODS+10) );	\

#define SPY_ENTRY(NUM)	\
	_StubVTblLocal[NUM] = (TFn_StubFunction)_SpyStub##NUM;	\

#define SPY_ENTRY_(FUNC_NAME,NUM) \
	_StubVTblLocal[NUM] = (TFn_StubFunction)FUNC_NAME;	\


#define SPY_END_VTBL()	\
	*pOrigVTable = _StubVTblLocal;	\
}	\

#define END_IMPL_SPY()	}

#define SET_SPY(NAME,OBJECT_PTR)	NAME##NS::AttachSpy( OBJECT_PTR )


#define CALL_METHOD(NUM)			\
	__asm{ lea eax, _StubVTbl }		\
	__asm{ mov eax, [eax+NUM*4] }	\
	__asm {	call eax }				\

#define GET_RET_VAL(VAR_NAME)	\
	__asm{ mov VAR_NAME, eax }	\


#define CALL_METHOD1(NUM,PARM1)	\
	__asm{ push PARM1 }			\
	CALL_METHOD(NUM)			\


#define CALL_METHOD2(NUM,PARM1,PARM2)	\
	__asm{ push PARM2 }					\
	CALL_METHOD1(NUM,PARM1)				\


#define CALL_METHOD3(NUM,PARM1,PARM2,PARM3)	\
	_asm{ push PARM3 }						\
	CALL_METHOD2(NUM,PARM1,PARM2)			\

#define CALL_METHOD4(NUM,PARM1,PARM2,PARM3,PARM4)	\
	_asm{ push PARM4 }								\
	CALL_METHOD3(NUM,PARM1,PARM2,PARM3)				\


#define DECL_QI_FILTER(NAME) \
static GUID NAME##GUID_Tbl[10];		\
BOOL NAME##QueryInterfaceFilter( HRESULT hr, GUID* pGuid )	\
{	\
	static int iIndx = -1;	\
	if ( iIndx == -1 )	\
	{						\
		ZeroMemory( NAME##GUID_Tbl, sizeof(NAME##GUID_Tbl) );	\
		iIndx = 0;	\
	}		\
	if ( hr == S_OK )	\
	{					\
		for( int i(0); i < iIndx; i++ )	\
		{					\
			if ( NAME##GUID_Tbl[i] == *pGuid )	\
			{			\
				return FALSE;	\
			}	\
		}		\
		NAME##GUID_Tbl[iIndx] = *pGuid;	\
		if ( iIndx < 10 )		\
		{						\
			iIndx ++;			\
		}						\
		CDbg::Trace("       " #NAME "::QueryInterface( " );	\
		CDbg::TraceGuid( *pGuid, FALSE );		\
		CDbg::Trace(" )...\n" );			\
		return TRUE;						\
	}										\
	return FALSE;							\
}											\

#define FILTER_QI(HRES,PGUID,NAME) NAME##QueryInterfaceFilter(HRES,PGUID)

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
United States United States
For the last 7 years I have developed software in real-time/embedded and MS-Windows environments for military and civil markets. I hold B.Sc. degree in computer engineering. Living in Ontario, Canada, I like hiking and traveling in general. Currently, I'm looking for employment opportunity inside the GTA.

Comments and Discussions