Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5839031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:31:55+00:00 2026-05-22T11:31:55+00:00

I am making a tutorial based program and want to be able to hook

  • 0

I am making a tutorial based program and want to be able to hook my code into certain apps to get the tutorial interacting with the app.

My hook code works for most apps except google chrome. I have stripped my code down to the following so you can see it going wrong.

Main.cpp

#include <Windows.h>
#include <iostream>
#include <psapi.h>
#include <Tlhelp32.h>

unsigned long GetProcId( const std::string& name )
{
    unsigned long res = 0 ;

    HANDLE hSnapShot=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
    PROCESSENTRY32 processInfo ;
    processInfo.dwSize=sizeof(PROCESSENTRY32W);

    if( !Process32First( hSnapShot, &processInfo ) )
    {
        CloseHandle( hSnapShot ); 
        return res ;
    }

    do 
    {
        if( NULL != ( strstr ( strlwr ( processInfo.szExeFile ), name.c_str() ) ) )
        {               
            res = processInfo.th32ProcessID ;
            break ;
        }
    } while(Process32Next( hSnapShot,&processInfo ));

    CloseHandle( hSnapShot ) ;
    return res ;
}

typedef LRESULT (CALLBACK *DllHookProc)(int nCode, WPARAM wParam, LPARAM lParam);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
               LPSTR lpCmdLine, int nCmdShow)
{
    unsigned int processid = GetProcId( "chrome.exe" ) ;

    if (processid == 0)
    {
        return 0 ;
    }

    HINSTANCE dllInstance = LoadLibrary("mydll.dll") ;

    if (dllInstance == NULL)
    {
        return 0 ;
    }

    DllHookProc hookProc = (DllHookProc)::GetProcAddress(dllInstance, "HookProc");

    if ( hookProc == NULL) 
    {
        FreeLibrary(dllInstance);
        return 0 ;
    }

    HHOOK hook = SetWindowsHookEx(WH_CALLWNDPROC,(HOOKPROC)hookProc,
        dllInstance, processid );

    if (hook == NULL)
    {
        FreeLibrary(dllInstance);
        return 0 ;
    }

    return 0 ;
}

Test Dll (mydll.dll)

LRESULT CALLBACK HookProc (int nCode, WPARAM wParam, LPARAM lParam )
{
    //Pass to the next chain in the process list
    return CallNextHookEx( 0, nCode, wParam, lParam);
}

BOOL APIENTRY DllMain(HANDLE hModule, DWORD dwReason, LPVOID lpReserved)
{
    return TRUE;
}

Definition file

LIBRARY "MYDLL"
EXPORTS
HookProc @1

Everything works fine (including getting processId and loading library and getprocaddress) up to the SetWindowsHookEx which returns NULL with error code 87 (invalid parameter).

Both chrome.exe and my code are 32 bit.

Does this work for anyone else or does anyone know what it doesnt work?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T11:31:55+00:00Added an answer on May 22, 2026 at 11:31 am

    One possible problem would be if you’re building 64bit code, but chrome.exe is 32bit (or the other way around). [See comment & update, this is not the case.]


    One suspicious thing in your code is that you’re not calling Process32First, and that seems to be required. See for ex: Taking a Snapshot and Viewing Processes.


    Last suggestion: you’re passing in a process id to SetWindowsHookEx, but that expects a thread id.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am making a sample program in hibernate follow this tutorial: http://www.myeclipseide.com/documentation/quickstarts/hibernateintroduction/ using reverse
I'm making some basic drop down menus based on this tutorial So its all
I'm in the process of making an Android 3 app that has a tab-based
I am just in the process of making some little demo tutorial videos for
I need just a basic example or tutorial of making a mobile phone and
I found a tutorial from nettuts and it has a source code in it
I am making use of PHPMailer to send mail through GMail. The code I
Apple has a nice little tutorial for making a simple master-detail interface. Interface Builder
I have been making several projects to compile small SDL code tutorials from a
I'm looking for a tutorial on how to embed Wordpress into a webpage e.g

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.