hook.dll capture information into the problem of error

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I developed a program to retrieve the window information.

When the hook into the error occurred.

First, I hook is written in C + + in VB.net then invoke.

This is my purpose in this window WM_PSD_ENVSTAMPRECT get hwnd2 the lparam value.

<div style="color:black; background-color:white
<pre><span style="color:green -------------------------------------------------
<span style="color:green Call hook Services

<span style="color:blue Declare <span style="color:blue Function PaintHookProc <span style="color:blue Lib <span style="color:#a31515 "hookps.dll" (<span style="color:blue ByVal hwnd <span style="color:blue As IntPtr, <span style="color:blue ByVal uMsg <span style="color:blue As <span style="color:blue UInteger, <span style="color:blue ByVal wParam <span style="color:blue As IntPtr, <span style="color:blue ByVal lParam <span style="color:blue As IntPtr) <span style="color:blue As <span style="color:blue Integer

<span style="color:blue Declare <span style="color:blue Function SetHook <span style="color:blue Lib <span style="color:#a31515 "hookps.dll" (<span style="color:blue ByVal hwnd <span style="color:blue As IntPtr) <span style="color:blue As <span style="color:blue Integer

<span style="color:blue Declare <span style="color:blue Function ReleaseHook <span style="color:blue Lib <span style="color:#a31515 "hookps.dll" () <span style="color:blue As <span style="color:blue Long

<span style="color:blue Declare <span style="color:blue Function GetlParam <span style="color:blue Lib <span style="color:#a31515 "hookps.dll" (<span style="color:blue ByVal lParam <span style="color:blue As IntPtr) <span style="color:blue As <span style="color:blue Integer


<span style="color:blue Private <span style="color:blue Sub Button4_Click (<span style="color:blue ByVal sender <span style="color:blue As System.Object, <span style="color:blue ByVal e <span style="color:blue As System.EventArgs) <span style="color:blue Handles Button4.Click <span style="color:green into the hook

<span style="color:blue Dim hwnd0 <span style="color:blue As IntPtr = GetDesktopWindow ()
<span style="color:blue Dim hwnd1 <span style="color:blue As IntPtr = FindWindowEx (hwnd0, 0, <span style="color:#a31515 "ThunderRT6FormDC", vbNullString) <span style="color:green find the fw this window
<span style="color:blue Dim hwnd2 <span style="color:blue As IntPtr = FindWindowEx (hwnd1, 0, <span style="color:#a31515 "Slider20WndClass", vbNullString)
<span style="color:blue Dim um <span style="color:blue As <span style="color:blue Long
<span style="color:blue Dim wpa <span style="color:blue As IntPtr

SetHook (hwnd2) <span style="color:green into the hook
PaintHookProc (hwnd2, um, wpa, lpm) <span style="color:green get hook data

<span style="color:blue End <span style="color:blue Sub
[/code]

<br/>
--------------------------------------------------------------------
However, when the hook into, then an error occurred

Here is the error message:

Unable to load DLL hookps.dll: can not find the specified module. (Exception from HRESULT: 0x8007007E)

I do not know which side is the hook I have nothing wrong.

Here is my C + + code:

<div style="color:black; background-color:white
<pre>/ Hookps.cpp: Custom DLLs exported function application.
/ /
# Include <windows.h>
# Include <span style="color:#a31515 "stdafx.h"
# Include <span style="color:#a31515 "hookps.h"

<span style="color:green //------------------------------------
# Define WINAPI_stdcall
# Define WM_PSD_ENVSTAMPRECT (WM_USER +5)
# Define WM_USER 0x0400

<span style="color:green //----------------------------------------
/ / Shared variable
# Pragma data_seg (<span style="color:#a31515 ". Shared")

HWND g_hWnd = 0;
HHOOK hThisHook = 0;
LPARAM lparamvalue = 0;
/ / Save the hook handle
/ / Static UINT_PTR CALLBACK PaintHookProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
/ / Int GetWindowTextRemote (HWND hwnd, LPSTR lpString);
/ / Int ReleaseHook ();

# Pragma data_seg ()
# Pragma comment (linker, <span style="color:#a31515 "/ section:. Shared, RWS")


<span style="color:green //------------------------------------------------ --------------------------------
/ / Export function
/ / # Define DllExport __declspec (<span style="color:blue dllexport) <span style="color:blue static UINT_PTR CALLBACK PaintHookProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

/ / # Define DllExport2 __declspec (<span style="color:blue dllexport) <span style="color:blue int GetWindowTextRemote (HWND hwnd, LPSTR lpString);

/ / # Define DllExport3 __declspec (<span style="color:blue dllexport) <span style="color:blue int ReleaseHook ();


<span style="color:green //------------------------------------------------ ---------



<span style="color:blue long (CALLBACK __stdcall PaintHookProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)) / / Message callback function
{

/ / Char <span style="color:blue value = 0; / / lParam is 16bit
<span style="color:blue switch (uMsg)
{
<span style="color:blue case WM_PSD_ENVSTAMPRECT:
/ / URet = PreDrawPage (WORD (wParam), WORD (wParam), (LPPAGESETUPDLG) lParam);
/ / Value = lParam;
lparamvalue = lParam;


<span style="color:blue break;
<span style="color:blue return TRUE;
<span style="color:blue default:
<span style="color:blue return FALSE;
};
<span style="color:blue return TRUE;
};
<span style="color:green //----------------------------------
HINSTANCE hDll;



/ / Set the mount hook
<span style="color:blue long (__stdcall SetHook (HWND hwnd))
{
g_hWnd = hwnd;
hThisHook = SetWindowsHookEx (WH_CALLWNDPROC, (HOOKPROC) PaintHookProc, hDll, GetWindowThreadProcessId (hwnd, NULL));


<span style="color:blue if (hThisHook == NULL)
{
MessageBox (NULL, L <span style="color:#a31515 "hook failed", L <span style="color:#a31515 "title window hook failed", MB_OK);
<span style="color:blue return FALSE;
}

<span style="color:blue return TRUE;
};
/ /

<span style="color:blue long (__stdcall GetlParam (LPARAM lParam))
{
lParam = lparamvalue;
<span style="color:blue return TRUE;
};

<span style="color:blue int (__stdcall ReleaseHook ()) / / <<<<<< Off the hook
{
<span style="color:blue if (hThisHook)
{
UnhookWindowsHookEx (hThisHook);
hThisHook = NULL;
}
<span style="color:blue return TRUE;
};
/ / Enum
/ / {
/ / HM_CALLWNDPROC = 0x0001,
/ /};

[/code]

<br/>
<br/>


The hook I used depends, to check the hook of the four exported functions have been no problem.

Has been correctly derived.

I upload the files to skydriver your reference:


<ol>
<span style="font-family:simsun; line-height:22px <a title="hook https://skydrive.live.com/redir.aspx?cid=105b2868cb2df559&resid=105B2868CB2DF559!190
</ol>

<br/>

View the full article
 
Back
Top