Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <detours.h>
- // define a typedef for the original function
- typedef int(WINAPI* PMessageBox)(HWND, LPCWSTR, LPCWSTR, UINT);
- // define the function pointer for the original function
- PMessageBox pMessageBox = MessageBoxW;
- // define the replacement function
- int WINAPI MyMessageBox(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType)
- {
- return pMessageBox(hWnd, L"Hello from hooked function!", lpCaption, uType);
- }
- int main()
- {
- // detour the MessageBoxW function to our replacement function
- DetourTransactionBegin();
- DetourUpdateThread(GetCurrentThread());
- DetourAttach(&(LPVOID&)pMessageBox, MyMessageBox);
- DetourTransactionCommit();
- // call the hooked function
- MessageBoxW(NULL, L"Hello world!", L"Greetings", MB_OK);
- // remove the hook and exit
- DetourTransactionBegin();
- DetourUpdateThread(GetCurrentThread());
- DetourDetach(&(LPVOID&)pMessageBox, MyMessageBox);
- DetourTransactionCommit();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement