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 1027455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:14:35+00:00 2026-05-16T12:14:35+00:00

Trying to write a GLOBAL CBT HOOK, this is My code, but my hooking

  • 0

Trying to write a GLOBAL CBT HOOK,
this is My code, but my hooking app doesn’t recieve any Messages, neither writes the dll something to a test file.

This is My Code:

#include "stdafx.h"

#include "GlobalHook.h"


#include "Stdafx.h"

#include <iostream>
#include <fstream>

#define DLL_EXPORT
#include "GlobalHook.h"
#include <windows.h>
using namespace std;

#pragma comment(lib, "User32.lib")
#pragma unmanaged

HINSTANCE dllHandle;  
#pragma data_seg("ASEG")  
    HWND prnt = 0;  
#pragma data_seg()  
#pragma comment(linker, "/section:ASEG,RWS")  
    HHOOK hHook;  
    int x = 0;  

BOOL APIENTRY DllMain(    
         HINSTANCE hinstDLL,  // handle to DLL module  
         DWORD fdwReason,     // reason for calling function  
         PVOID lpReserved )  // reserved  
{
    // Perform actions based on the reason for calling.  
    switch( fdwReason )  
    {  
    case DLL_PROCESS_ATTACH:    
        dllHandle = hinstDLL;    
        return TRUE;  
        break;  
    }  
}  
   LRESULT CALLBACK CBTProc(int nCode, WPARAM wParam, LPARAM lParam)  
   {
        if(nCode < 0)
        {
            return CallNextHookEx(hHook, nCode, wParam, lParam);
        }
        if(nCode == HCBT_MINMAX)
        {
            SendNotifyMessage(prnt, WM_USER + 3, wParam, lParam);
            if(x == 0)
            {
                ofstream myfile;
                myfile.open ("C:\\example.txt");
                myfile << "Dies in ein File.";
                myfile.close();
                x = 1;
            }
        }
        return CallNextHookEx(hHook, nCode, wParam, lParam);
   }
extern "C"
{
   DECLDIR int SetHook( HWND parent )
   {
       prnt = parent;
        hHook = SetWindowsHookEx(WH_CBT, CBTProc, dllHandle, 0);
        return 1;
   }
   DECLDIR void UninstallHook( void )
   {
      if(UnhookWindowsHookEx(hHook))
      {

      }
   }
   DECLDIR int Add(int a, int b)
   {
       return (a + b);
   }
}
  • 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-16T12:14:36+00:00Added an answer on May 16, 2026 at 12:14 pm

    The general structure seems sound.

    #pragma comment(linker, "/section:ASEG,RWS") RWS might need to be rws

    I’d strip down CBTProc so that you just log to file for the moment on every minmax, this would allow you to see that your dll has been injected properly.

    WM_USER is ment to be used within a single app not across apps (though you can get away with it). Consider RegisterWindowMessage()

    If the injected App is a lower priv level you may need to force your recieving app to allow contact from the lower priv app using ChangeWindowMessageFilter

    Also might try also hooking WH_CALLWNDPROC, WH_GETMESSAGE to see if you can get other messages through.

    Your window will also be hooked, make sure you don’t get into a message sending loop.
    You are using SendMessage to forward the message, it will cause the message pump of the app to block, if that app is also your own processing the message you will lock.

    indllmain you could use outputdebug to log what apps the dll is being loaded into

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

Sidebar

Related Questions

I was trying to write a code to handle exceptions, but overriding another exception
I'm trying to write some xml by this piece of code docs = XmlReportGenerator()
I'm trying to write some xml by this piece of code docs = XmlReportGenerator()
Im trying to write a simple F# ASP.Net MVC app Ive added the Global.asax
I am trying to figure out how well the global memory write accesses of
I m trying write code that after reset set up rrpmax as 3000. It
I am trying write a function that generates simulated data but if the simulated
Trying to write app for service technicians that will display open service calls within
Trying to write out syslog entries containing strings but they don't register. // person.name
Trying to write a code at the moment that basically tests to see if

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.