Click here to Skip to main content
Click here to Skip to main content

APIHijack - A Library for easy DLL function hooking.

By , 15 Sep 2000
Rate this:
Please Sign up or sign in to vote.
  • Download source files and demo project - 102 Kb


    Based on DelayLoadProfileDLL.CPP, by Matt Pietrek for MSJ February 2000. This code is intended to be included in a DLL inserted through a global Windows Hook (CBT hook for example). It will replace functions from other DLLs (e.g. DDRAW.DLL) with functions from your DLL.

    Functions are hooked by passing a parameter structure to the HookAPICalls() function as follows:

    SDLLHook D3DHook = 
        false, NULL,    // Default hook disabled, NULL function pointer.
            { "DirectDrawCreate", MyDirectDrawCreate },
            { NULL, NULL }
    BOOL APIENTRY DllMain( HINSTANCE hModule, DWORD fdwReason, LPVOID lpReserved)
        if ( fdwReason == DLL_PROCESS_ATTACH )  // When initializing....
            hDLL = hModule;
            // We don't need thread notifications for what we're doing.  Thus, 
            // get rid of them, thereby eliminating some of the overhead of 
            // this DLL
            DisableThreadLibraryCalls( hModule );
            // Only hook the APIs if this is the right process.
            GetModuleFileName( GetModuleHandle( NULL ), Work, sizeof(Work) );
            PathStripPath( Work );
            if ( stricmp( Work, "myhooktarget.exe" ) == 0 )
                HookAPICalls( &D3DHook );
        return TRUE;

    Now all that remains is to get your DLL loaded into the target process.

  • License

    This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    About the Author

    Wade Brainerd

    United States United States
    No Biography provided

    Comments and Discussions

    QuestionNon-Debug applications can be hooked too ? PinmemberRyouku12-Jul-09 18:17 
    GeneralProblem when trying to hook text functions PinmemberRoey C31-Mar-08 9:25 
    Hi everyone Smile | :)
    I'm trying to use this library to retrieve text from all kind of windows.
    but for some reason i only get only parts of the text.
    for example: in notepad i only get the texts in the menu, but not what the user has written.
    does anyone knows why?
    i hooked these functions:
    thanks in advance Smile | :)
    Don't believe to what you hear on the news...

    GeneralIt does not work for me. PinmemberAchilleas Margaritis27-Nov-07 23:09 
    GeneralRe: It does not work for me. PinmemberMXT320-Jan-12 7:42 
    Generalnot imported by name?! PinmemberParallan3-Nov-07 23:27 
    QuestionHow to hook user defined DLL ? Pinmembermahesh kumar s3-Jul-07 1:46 
    Generalmonitoring dll function calls Pinmembermahesh kumar s28-Jun-07 4:04 
    Questionthis trick doesn't work with all programs, nor? Pinmember6r15u30-Jan-07 2:10 
    QuestionAPIHijack is outmoded? Pinmemberplayer.24-Jul-06 22:51 
    GeneralCompile with Visual Studio 2003 PinmemberP Gibson7-Jul-06 1:30 
    GeneralHooking LoadLibraryA PinmemberRed XIII28-Jun-06 0:58 
    GeneralVB.Net and APIHijack PinmemberVitoto12-Jan-06 5:36 
    GeneralThe demo Pinmembertriplebit21-Nov-05 1:07 
    GeneralThe demo Pinmembertriplebit21-Nov-05 1:06 
    GeneralPurely excelent... PinmemberNick Z.3-Nov-05 14:21 
    AnswerRe: Purely excelent... PinmemberNguyen Duc Minh19-Nov-05 20:01 
    Questionhow to hook copy,cat,past operations PinmemberAl_Shakhly1-Nov-05 22:15 
    GeneralRetreiving variable PinmemberKrisse14-Aug-05 4:04 
    GeneralHooking dynamicly loaded DLLs functions Pinmemberseybold23-May-05 22:33 
    GeneralRe: Hooking dynamicly loaded DLLs functions Pinmemberdchris_med14-Feb-06 3:16 
    GeneralLooking like a atlternative of DsSubCls.dll PinmemberThatsAlok3-Dec-04 19:10 
    GeneralHooked function address is replaced by Original one Pinmemberkeenalex23-Sep-04 20:07 
    GeneralRe: Hooked function address is replaced by Original one PinmemberGareth Haslip11-Oct-04 2:32 
    GeneralRe: Hooked function address is replaced by Original one Pinmembersturlamolden12-Oct-06 12:58 
    GeneralCallbacks from inside PinmemberK-ballo20-Aug-04 14:34 
    Generalcan't do it for . . . Pinmembereuacela8-Aug-04 10:36 
    GeneralRe: can't do it for . . . Pinmemberflaming_red_dingo2-Apr-05 3:38 
    Generallicense PinsussSAITO,A21-Jul-04 3:02 
    GeneralRe: license PinmemberRoey C29-Mar-08 18:15 
    QuestionHow to hook DELAY IMPORT Address Table Pinmemberkyo9721-Jun-04 4:06 
    AnswerRe: How to hook DELAY IMPORT Address Table Pinmemberyuvalaviguy24-Nov-04 23:05 
    AnswerRe: How to hook DELAY IMPORT Address Table Pinmemberflaming_red_dingo2-Apr-05 3:43 
    QuestionHow can i hook com methods Pinmemberimranlodhi26-May-04 1:03 
    AnswerRe: How can i hook com methods Pinmemberautodebug19-Jul-04 17:23 
    QuestionHow can I change the characters of a message after hooking ? PinmemberRupom24-May-04 22:01 
    GeneralCreating toolbar Pinmemberpawan_ind_bly5-Apr-04 9:08 
    GeneralRe: Creating toolbar Pinmemberdorutzu9-Jun-04 6:26 
    GeneralRe: Creating toolbar PinmemberThatsAlok3-Dec-04 19:09 
    GeneralRe: Creating toolbar PinsussAnonymous28-Dec-04 23:35 
    GeneralCapture Text in RichEdit and HTML Pinmemberminhvc7-Mar-04 16:39 
    QuestionHow to remove hook Pinmemberminhvc19-Feb-04 15:53 
    AnswerRe: How to remove hook Pinmemberminhvc7-Mar-04 16:36 
    GeneralRe: How to remove hook PinmemberRoey C29-Mar-08 19:01 
    AnswerResetIAT & UnhookAPICalls Pinmemberdeodiaus26-May-05 7:03 
    GeneralRe: ResetIAT & UnhookAPICalls PinmemberRoey C29-Mar-08 19:17 
    AnswerRe: How to remove hook [modified] PinmemberRoey C29-Mar-08 18:22 
    Questionhow to know some button are pressed use hook Pinmembertang1000716-Feb-04 5:31 
    AnswerRe: how to know some button are pressed use hook PinsussRupom/RUET, Bangladesh7-Jun-04 20:04 
    GeneralUnHook!!!!! PinmemberMinVC15-Feb-04 15:04 
    GeneralEncrypted Pinsusskhossy14-Feb-04 23:50 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

    | Advertise | Privacy | Mobile
    Web04 | 2.8.140415.2 | Last Updated 16 Sep 2000
    Article Copyright 2000 by Wade Brainerd
    Everything else Copyright © CodeProject, 1999-2014
    Terms of Use
    Layout: fixed | fluid