#include <stdio.h>
class CSource
{
public:
__event void MyEvent(int nValue);
};
class CReceiver
{
public:
void MyHandler(int nValue)
{
printf_s("MyHandler1 was called with value %d./n", nValue);
}
void hookEvent(CSource* pSource)
{
__hook(&CSource::MyEvent, pSource, &CReceiver::MyHandler);
}
void unhookEvent(CSource* pSource)
{
__unhook(&CSource::MyEvent, pSource, &CReceiver::MyHandler);
}
};
int main() {
CSource source;
CReceiver receiver;
receiver.hookEvent(&source);
__raise source.MyEvent(123);
receiver.unhookEvent(&source);
}
當程序執行到__raise source.MyEvent(123)時,程序就會跳到 void MyHandler(int nValue)
執行printf_s("MyHandler1 was called with value %d./n", nValue)。簡單的用法!
本文來自CSDN博客,轉載請標明出處:http://blog.csdn.net/Dalek/archive/2010/04/20/5502624.aspx?