在官网下了detours.msi 安装后无法使用 用的ide 是dev c++  请问在 dev
C++ 下如何使用detours 编程
谢谢了

解决方案 »

  1.   

    使用VC6的命令行编译detours,会生成dll和lib,在dev c++调用detours.dll即可。
      

  2.   

    #include "stdafx.h"
    #include "DetourHook.h"
    #include <detours.h>#pragma comment(lib, "detours.lib") 
    #pragma comment(lib, "detoured.lib")static int (WINAPI* OLD_MessageBoxW)(HWND hWnd,LPCWSTR lpText,LPCWSTR lpCaption,UINT uType)=MessageBoxW;
    int WINAPI NEW_MessageBoxW(HWND hWnd,LPCWSTR lpText,LPCWSTR lpCaption,UINT uType)
    {
                    
            //修改输入参数,调用原函数
            int ret=OLD_MessageBoxW(hWnd,L"输入参数已修改",L"[测试]",uType);
            return ret;
    }VOID Hook()
    {
            DetourRestoreAfterWith();
            DetourTransactionBegin();
            DetourUpdateThread(GetCurrentThread());        //这里可以连续多次调用DetourAttach,表明HOOK多个函数
            DetourAttach(&(PVOID&)OLD_MessageBoxW,NEW_MessageBoxW);        DetourTransactionCommit();
    }VOID UnHook()
    {
            DetourTransactionBegin();
            DetourUpdateThread(GetCurrentThread());
            
            //这里可以连续多次调用DetourDetach,表明撤销多个函数HOOK
            DetourDetach(&(PVOID&)OLD_MessageBoxW,NEW_MessageBoxW);        DetourTransactionCommit();}
    int APIENTRY _tWinMain(HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPTSTR    lpCmdLine,
                         int       nCmdShow)
    {
            MessageBoxW(0,L"正常消息框",L"测试",0);
            Hook();
            MessageBoxW(0,L"正常消息框",L"测试",0);
            UnHook();
            return 0;
            
    }
    上面是VC的代码
    dev你参考下吧
      

  3.   

    我没有vc 啊
    请问在dev 下如何 编写 detours 的lib和dll xiexie
      

  4.   

    你还是放弃吧 dev 太老了
      

  5.   

    一样的,你只要包含对应的lib和h即可。