Hook doesn't work with 5.6

Just starting out? Need help? Post your questions and find answers here.
Stefou
User
User
Posts: 19
Joined: Thu May 29, 2008 8:40 am

Hook doesn't work with 5.6

Post by Stefou »

Hello
This code is good with PB 5 but not with PB5.6...maybe a bug ...???? :?

Thank you to have a look :)

Program:

Code: Select all

OpenWindow(0,0,0,300,200,"Test_Hook");,#PB_Window_Invisible)

hDLL = OpenLibrary(0, "hook_detection_pc.dll")
Debug hDLL
hmyHookHookKeyboard = SetWindowsHookEx_(#WH_KEYBOARD 	, GetProcAddress_(hDLL, "HookKeyboard"), hDLL, 0)
hmyHookHookMouse = SetWindowsHookEx_(#WH_MOUSE 	, GetProcAddress_(hDLL, "HookMouse"), hDLL, 0)


InitNetwork()


Repeat
  
  event=WaitWindowEvent()
  If event<>0
    Debug "event="+event
  EndIf
  
  Select event
      
    Case #WM_USER+6 ;{Hook Mouse
      Debug "Mouse"

      
      ;}
    Case #WM_USER+5 ;{ HOOK CLAVIER
      Debug "Clavier"

      
      
  EndSelect
  
Until event=#PB_Event_CloseWindow
DLL(seam OK):

Code: Select all

ProcedureDLL.S WindowsEnum()
  Static Flag,hWnd
  
  Repeat
    If Flag=0
      hWnd = FindWindow_( 0, 0 )
      Flag=1
    Else
      hWnd = GetWindow_(hWnd, #GW_HWNDNEXT)
    EndIf
    
    If hWnd <> 0
      If GetWindowLong_(hWnd, #GWL_STYLE) & #WS_VISIBLE = #WS_VISIBLE ; pour lister que les fenêtres visibles
        If GetWindowLong_(hWnd, #GWL_EXSTYLE) & #WS_EX_TOOLWINDOW <> #WS_EX_TOOLWINDOW ; pour lister que les fenêtres qui ne sont pas des ToolWindow ou barre d'outils
          retour.S = Space(256)
          GetWindowText_(hWnd, retour, 256)
          If retour<>"" : Break : EndIf
        EndIf
      EndIf
    Else
      Flag=0 
    EndIf
  Until hWnd=0
  
  ProcedureReturn retour  
EndProcedure
Procedure.S GetNomFenetreAvecDebut(Nom.S)
  ;debug "Procedure.s GetNomFenetreAvecDebut(Nom.s)"
  ;debug "Nom"
  retour$=""
  Repeat
    Temp.S=WindowsEnum()
    ;debug "Procedure.s GetNomFenetreAvecDebut :  "+ Temp
    If LCase(Left(Temp,Len(Nom)))=LCase(Nom)
      ;debug "Bingo : "+Temp
      retour$=Temp
    EndIf
    
  Until Temp=""
  ProcedureReturn retour$
EndProcedure

ProcedureDLL HookKeyboard(code.l, wParam.l, lParam.l)
  hMyWin = FindWindow_(0,"Test_Hook")
  
  If lParam<0 : type=0 : Else : type=1 : EndIf
  ;If GetNomFenetreAvecDebut("Confirmation")=""
    PostMessage_(hMyWin,#WM_USER+5,wParam,type)

  
  ProcedureReturn CallNextHookEx_(@HookKeyboard(), code, wParam, lParam)
EndProcedure

ProcedureDLL HookMouse(code.l, wParam.l, lParam.l)
  hMyWin = FindWindow_(0,"Test_Hook")
  
  *mymsg.MOUSEHOOKSTRUCT = lParam 
  *position.POINT=*mymsg\pt; MSG structure holds info
  
  
  ;SetClipboardText(action$)
  ;PokeS(adresse_message,action$)
  PostMessage_(hMyWin,#WM_USER+6,wParam,lParam)
  
  
  
  ProcedureReturn CallNextHookEx_(@HookMouse(), code, wParam, lParam)
EndProcedure
fryquez
Enthusiast
Enthusiast
Posts: 391
Joined: Mon Dec 21, 2015 8:12 pm

Re: Hook doesn't work with 5.6

Post by fryquez »

Not a bug. PB5.6 is Unicode only.

GetProcAddress_(hDLL, "HookKeyboard") fails because it needs a ASCII string.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Hook doesn't work with 5.6

Post by netmaestro »

You could go to the trouble of providing an Ascii version of the string but it's simpler to just replace GetProcAddress_() with the native GetFunction() and it will work.
BERESHEIT
Stefou
User
User
Posts: 19
Joined: Thu May 29, 2008 8:40 am

Re: Hook doesn't work with 5.6

Post by Stefou »

Thank you and sorry to had post in Bug.

Have a nice day
Post Reply