Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Error in CBT_HOOK function

Error in CBT_HOOK function

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    fu0
    wrote on last edited by
    #1

    i write a global CBT_HOOK function in a win32 DLL ,and i want to send a message to the DLL's calling windows.But it doesnt work. Here is my code: HWND hCallWnd = NULL; // a global var to save the Dll's Caller LRESULT CALLBACK CbtProc(int nCode,WPARAM wParam,LPARAM lParam) { switch(nCode) { case HCBT_CREATEWND: SendMessage(hCallWnd,MyMsgID,0,0); // to Send a msg break; } return CallNextProc(nCode,...); } void InstallHook(HWND hcallwnd) { SetWindowsHookEx(WH_CBT,CbtProc,DllHandle,0); // set a global hook hCallWnd = hcallwnd; // save the Caller's handle } the Error is : in InstallHook() function,the hCallWnd's value is correct. But in CALLBACK CbtProc() function, the hCallWnd's value is always ZERO! so my SendMessage() doesnt work at all. Who can point out reason ?

    M 1 Reply Last reply
    0
    • F fu0

      i write a global CBT_HOOK function in a win32 DLL ,and i want to send a message to the DLL's calling windows.But it doesnt work. Here is my code: HWND hCallWnd = NULL; // a global var to save the Dll's Caller LRESULT CALLBACK CbtProc(int nCode,WPARAM wParam,LPARAM lParam) { switch(nCode) { case HCBT_CREATEWND: SendMessage(hCallWnd,MyMsgID,0,0); // to Send a msg break; } return CallNextProc(nCode,...); } void InstallHook(HWND hcallwnd) { SetWindowsHookEx(WH_CBT,CbtProc,DllHandle,0); // set a global hook hCallWnd = hcallwnd; // save the Caller's handle } the Error is : in InstallHook() function,the hCallWnd's value is correct. But in CALLBACK CbtProc() function, the hCallWnd's value is always ZERO! so my SendMessage() doesnt work at all. Who can point out reason ?

      M Offline
      M Offline
      Mike Beckerleg
      wrote on last edited by
      #2

      The DLL is loaded into the address space of each process and each process gets a separate copy of the global variable. You need to put hCallWnd into a shared partition. See this article[^].

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups