Hooking Win32 API calls

Posted on 2009-02-21
Last Modified: 2013-12-03
Ah hello.

Simple question: I would like to learn how to hook a given Win32 call, so I can either deny the call, or replace the call with something else.  I don't want to do this for malicious purposes, I need this for my own application only.

For example, I want to hook the calls into ::MessageBox, for example.  This is so I can set up a another windows hook to watch for the window creation, then change, say, the text on the dialog, or the background colour of the dialog.  This is to prevent the need for a whole new class of dialog to be created, then replace every call to ::MessageBox with this new dialog, but also to catch message boxes displayed via MFC internally, eg those displayed during Serialization Fail ("Failed to load document").

(I asked a question similar to this a while ago, and was pointed at the Windows Theme API.  But I don't want to use that for many reasons that are not relevant here :) )

PS Any book titles that discuss this topic will also be welcomed.

Question by:mrwad99
    LVL 86

    Accepted Solution

    Take a look at ("API hooking revealed") - this article discusses that issue in-depth and comes with full source code.
    LVL 5

    Assisted Solution

    LVL 2

    Assisted Solution

    Just use Detours or read J. Richter's book and see his sampleq codes
    LVL 19

    Author Comment

    Greetings all.

    I have not forgotten about this question, I have been reading the links provided, which currently seem to be useful.  Castorix, you mention Jeffrey Richter's book - which book exactly?

    LVL 19

    Author Comment

    Thanks all.  By reading those articles I found a link to a sample project which does just this via the book "Programming Applications for Windows" by Jeffrey Richter; but I am having problems: if you could help at http:Q_24184290.html please do :)

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
    Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now