Coder Social home page Coder Social logo

memberfunctionhook's Introduction

MemberFunctionHook

主要功能是SetWindowsHookEx函数中可以使用C++成员函数作为回调函数。 主要**及实现代码来自http://blog.csdn.net/realzyc8847/article/details/6229350 我对他进行了简单的分解,将核心的成员函数转普通函数功能提取出来以便适用于更多场景。

  • 此模块需要运行数据段代码,需要关闭数据执行保护 /NXCOMPAT:NO  

例子

GamePageUi::GamePageUi()
{
	HookManager::Instance()->AddHook(BaseHook::Keyboard, GetCurrentThreadId(),
	std::bind(&GamePageUi::KeyboardHookProc, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
}
LRESULT GamePageUi::KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam)
{
	//屏蔽F10
	return (wParam == VK_F10) ? 1 : 0;
}

转换功能例子

//===============================================================
//将类成员函数指针转化为一般函数指针
LRESULT(CALLBACK * PCoreHookProcess)(int nCode, WPARAM wParam, LPARAM lParam);
MEMBERFUNCTION_TO_NORMALFUNCTION(this, &BaseHook::CoreHookProcess, &PCoreHookProcess);
//===============================================================
point_HookID = SetWindowsHookEx(GetHookType(), PCoreHookProcess, hMod, GetThreadId());

 依赖  

memberfunctionhook's People

Contributors

zhipeng515 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.