Hook souris

cs_breton51 Messages postés 78 Date d'inscription jeudi 21 avril 2005 Statut Membre Dernière intervention 15 novembre 2018 - 2 juil. 2008 à 18:20
Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 septembre 2021 - 2 juil. 2008 à 21:37
bonjour,

J'ai un petit probleme pour modifier un parram dans un hook souris, je suis sous vb 2005
mon code:
    PrivateDeclareFunction UnhookWindowsHookEx Lib"user32" (ByVal hHook AsInteger) AsInteger<?xml:namespace prefix o ns "urn:schemas-microsoft-com:office:office" /??>

    PrivateDeclareFunction SetWindowsHookEx Lib"user32"Alias"SetWindowsHookExA" (ByVal idHook AsInteger, ByVal lpfn As sourisHookDelegate, ByVal hmod AsInteger, ByVal dwThreadId AsInteger) AsInteger

 

    PrivateDeclareFunction CallNextHookEx Lib"user32" (ByVal hHook AsInteger, ByVal nCode AsInteger, ByVal wParam AsInteger, ByRef lParam As MouseHookStruct) AsInteger

    PrivateDelegateFunction sourisHookDelegate(ByVal Code AsInteger, ByVal wParam AsInteger, ByRef lParam As MouseHookStruct) AsInteger

 

    <MarshalAs(UnmanagedType.FunctionPtr)> Private callback As sourisHookDelegate

 

    PrivateMousHandle AsInteger

 

    PrivateConst WH_MOUSE_LL = 14

    PrivateConst WH_MOUSE = 7

    PrivateConst HC_ACTION AsInteger = 0

 

 

    PrivateStructure MouseHookStruct

        Privatept As Point

        Privatehwnd AsInteger

        PrivatewHitTestCode AsInteger

        PrivatedwExtraInfo AsInteger

    EndStructure

 

    PublicSub Hooksouris()

        callback = New sourisHookDelegate(AddressOf sourisCallback)

        MousHandle = SetWindowsHookEx( _

                            WH_MOUSE_LL, _

    callback,      _Marshal.GetHINSTANCE(Reflection.Assembly.GetExecutingAssembly().GetModules()(0)), _

                            0)

    EndSub

 

    PublicSub UnHooksouris()

        UnhookWindowsHookEx (MousHandle)

    EndSub

 

    PrivateFunction sourisCallback(ByVal Code AsInteger, _

  ByVal wParam AsInteger, _

  ByRef lParam As MouseHookStruct) AsInteger

       

  If (Code = HC_ACTION) Then

 

             traitemant quelconque

               lParam.pt.X = lParam.pt.X - 10

        EndIf

 

 

        Return CallNextHookEx(MousHandle, Code, wParam, lParam)

 

    EndFunction

le hook fonctionne bien car je recup les bons parrametres
le pb est qu'aucun changemant de parametre n'est pris en compte et je ne vois pas pourquoi
merci de votre aide.

1 réponse

Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 septembre 2021 74
2 juil. 2008 à 21:37
regarde là:
http://www.cppfrance.com/codes/HOOK-DLL-HOOK-FACILE-VB6_41774.aspx

voir main.cpp

et:

// idem que précedemment, jusqu'ici.
// nous allons reserver un peu de mémoire dans espace mémoire du client.
// Ensuite, nous allons y copier la structure pointée par lParam, afin que le client puisse y accéder.
// Nous lisons ensuite cette mémoire, afin que les éventuelles modifications effectuées par le client
// soient prises en compte

HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, false, pItem->ProcessID);
if (hProc != INVALID_HANDLE_VALUE)
{
LPVOID pData = VirtualAllocEx(hProc, NULL, vnLength, MEM_COMMIT, PAGE_READWRITE);

WriteProcessMemory(hProc, pData, (LPVOID)lParam, vnLength, NULL);
SendMessage(pItem->hCallBack, WM_USER + nCode, wParam, (LPARAM)pData);
ReadProcessMemory(hProc, pData, (LPVOID)lParam, vnLength, NULL);

VirtualFreeEx(hProc, pData, NULL, MEM_RELEASE);

CloseHandle(hProc);
}
0
Rejoignez-nous