// Created by Microsoft (R) C/C++ Compiler Version 13.10.3077 // // c:\documents and settings\divyanand\desktop\testing seminar\mithun\code\debugging injected code\attributes\attributes.mrg.cpp // compiler-generated file created 01/23/04 at 13:57:24 // // This C++ source file is intended to be a representation of the // source code injected by the compiler. It may not compile or // run exactly as the original source file. // //+++ Start Injected Code For Attribute 'event' #injected_line 13 ".\\Attributes.cpp" struct __EventingCriticalSectionStub { void Lock() { } void Unlock() { } }; #injected_line 13 ".\\Attributes.cpp" // injected template struct __eventingGetAddr { typedef void (T::*pmfn_type) (); typedef void (*pgfn_type) (); union U { void *addr; void (T::*pmfn)(); void (*pgfn)(); }; static pmfn_type __getMAddr(void *addr) { U u; u.addr = addr; return u.pmfn; } static void* __getVAddr(pmfn_type pmfn) { U u; u.pmfn = pmfn; return u.addr; } static pgfn_type __getSMAddr(void *addr) { U u; u.addr = addr; return u.pgfn; } static void* __getSVAddr(pgfn_type pgfn) { U u; u.pgfn = pgfn; return u.addr; } }; #injected_line 13 ".\\Attributes.cpp" struct __eventNode { virtual int __isEqual(void*, void*) = 0; virtual int __isEqual(void*) = 0; __eventNode* next; }; #injected_line 13 ".\\Attributes.cpp" struct __eventMainNode { int key; __eventNode* root_node; __eventMainNode* next_event; }; //--- End Injected Code For Attribute 'event' /*---------------------------------------------------------------------- Debugging Applications for Microsoft .NET and Microsoft Windows Copyright © 1997-2003 John Robbins -- All rights reserved. ----------------------------------------------------------------------*/ #include "stdafx.h" //+++ Start Injected Code [no_injected_text(true)]; // Suppress injected text, it has already been injected #pragma warning(disable: 4543) // Suppress warnings about skipping injected text #pragma warning(disable: 4199) // Suppress warnings from attribute providers // M00PRAGMA("\n\nNOTE: This merged source file should be visually inspected for correctness.\n\n") //--- End Injected Code // Set up the event source. This is basically the prototype for // an event. [ event_source ( native ) ] class CSource { public : __event void MyEvent ( int nValue ) ; //+++ Start Injected Code For Attribute 'event' #injected_line 13 ".\\Attributes.cpp" __EventingCriticalSectionStub __EventingCS; #injected_line 13 ".\\Attributes.cpp" struct __eventNode_CSource_MyEvent { virtual void __invoke(int i1) = 0; virtual int __isEqual(void*, void*) = 0; virtual int __isEqual(void*) = 0; __eventNode_CSource_MyEvent* next; }; template struct __InvokeHandlers_CSource_MyEvent : __eventNode_CSource_MyEvent { T* p; void ( T::*pmfn) (int i1); void __invoke(int i1) { return (p->*pmfn) (i1); } int __isEqual(void* p, void* pfn) { return ((T*) p == this->p) && (__eventingGetAddr::__getMAddr(pfn) == (void (T::*) ()) pmfn); } int __isEqual(void* p) { return ((T*) p == this->p); } }; __eventNode_CSource_MyEvent* __eventHandlerList_CSource_MyEvent; template long __AddEventHandler_CSource_MyEvent(T* pThis, void ( T::*pmfn) (int i1)) { __InvokeHandlers_CSource_MyEvent* newHead = new __InvokeHandlers_CSource_MyEvent; newHead->p = pThis; newHead->pmfn = pmfn; __EventingCS.Lock(); newHead->next = __eventHandlerList_CSource_MyEvent; __eventHandlerList_CSource_MyEvent = (__eventNode_CSource_MyEvent*) newHead; __EventingCS.Unlock(); return 0; } template long __RemoveEventHandler_CSource_MyEvent(T* pThis, void ( T::*pmfn) (int i1)) { __EventingCS.Lock(); __eventNode_CSource_MyEvent* node = __eventHandlerList_CSource_MyEvent; __eventNode_CSource_MyEvent* prev = 0; for (; node != 0; node = node->next) { if (node->__isEqual(pThis, __eventingGetAddr::__getVAddr((void (T::*) ()) pmfn)) != 0) { if (prev == 0) { __eventHandlerList_CSource_MyEvent = node->next; } else { prev->next = node->next; } delete node; __EventingCS.Unlock(); return 0; } prev = node; } __EventingCS.Unlock(); return 1; } template void __RemoveAllEventHandlers_CSource_MyEvent(T* pThis) { __EventingCS.Lock(); __eventNode_CSource_MyEvent* node = __eventHandlerList_CSource_MyEvent; __eventNode_CSource_MyEvent* prev = 0; while (node != 0) { if (node->__isEqual(pThis) != 0) { __eventNode_CSource_MyEvent* dead = node; if (prev == 0) { __eventHandlerList_CSource_MyEvent = node = node->next; } else { prev->next = node = node->next; } delete dead; } else { prev = node; node = node->next; } } __EventingCS.Unlock(); } #injected_line 13 ".\\Attributes.cpp" CSource() { __eventHandlerList_CSource_MyEvent = 0; } #injected_line 13 ".\\Attributes.cpp" void __RemoveAllEventHandlers(void* pThis) { __RemoveAllEventHandlers_CSource_MyEvent(pThis); } //--- End Injected Code For Attribute 'event' } ; //+++ Start Injected Code For Attribute 'event' #injected_line 13 ".\\Attributes.cpp" inline void CSource::MyEvent(int i1) { __EventingCS.Lock(); __eventNode_CSource_MyEvent* node = __eventHandlerList_CSource_MyEvent; for (; node != 0; node = node->next) { node->__invoke(i1); } __EventingCS.Unlock(); } //--- End Injected Code For Attribute 'event' [ event_receiver ( native) ] class CReceiver { public : void MyHandler1 ( int nValue ) { _tprintf ( _T ( "MyHandler1 was called with value %d.\n" ) , nValue ) ; } void MyHandler2(int nValue) { _tprintf ( _T ( "MyHandler2 was called with value %d.\n" ) , nValue ) ; } void hookEvent(CSource* pSource) { __hook ( &CSource::MyEvent , pSource , &CReceiver::MyHandler1 ) //+++ Start Injected Code For Attribute 'hook' from CReceiver::hookEvent #injected_line 32 ".\\Attributes.cpp" (pSource)->__AddEventHandler_CSource_MyEvent((CReceiver*) this, &CReceiver::MyHandler1) //--- End Injected Code For Attribute 'hook' ; __hook ( &CSource::MyEvent , pSource , &CReceiver::MyHandler2 ) //+++ Start Injected Code For Attribute 'hook' from CReceiver::hookEvent #injected_line 33 ".\\Attributes.cpp" (pSource)->__AddEventHandler_CSource_MyEvent((CReceiver*) this, &CReceiver::MyHandler2) //--- End Injected Code For Attribute 'hook' ; } void unhookEvent(CSource* pSource) { __unhook ( &CSource::MyEvent , pSource , &CReceiver::MyHandler1 ) //+++ Start Injected Code For Attribute 'unhook' from CReceiver::unhookEvent #injected_line 38 ".\\Attributes.cpp" (pSource)->__RemoveEventHandler_CSource_MyEvent((CReceiver*) this, &CReceiver::MyHandler1) //--- End Injected Code For Attribute 'unhook' ; __unhook ( &CSource::MyEvent , pSource , &CReceiver::MyHandler2 ) //+++ Start Injected Code For Attribute 'unhook' from CReceiver::unhookEvent #injected_line 39 ".\\Attributes.cpp" (pSource)->__RemoveEventHandler_CSource_MyEvent((CReceiver*) this, &CReceiver::MyHandler2) //--- End Injected Code For Attribute 'unhook' ; } }; #ifdef _UNICODE int wmain ( void ) #else int main ( void ) #endif { CSource source ; CReceiver receiver ; receiver.hookEvent ( &source ) ; __raise source.MyEvent ( 123 ) ; receiver.unhookEvent ( &source ) ; }