I am using VB.net to develop an application, but there needs to be applied to the dll technology.

So come here to seek help.

First I will describe the features I need this dll

I want to monitor an application's window to get in on a PSD_ENVSTAMPRECT the lParam value.

Here I use SPY + + to monitor the application's window to get that information.

<00031> 00020E46 S WM_PSD_ENVSTAMPRECT wParam: 00000001 lParam: 00000001 <<<1
<00032> 00020E46 R WM_PSD_ENVSTAMPRECT lResult: 00000000
<00033> 00020E46 S WM_PSD_PAGESETUPDLG wParam: 00000000 lParam: 00000000
<00034> 00020E46 R WM_PSD_PAGESETUPDLG lResult: 00000001
<00035> 00020E46 S WM_PSD_ENVSTAMPRECT wParam: 00000001 lParam: 00000002 <<<2
<00036> 00020E46 R WM_PSD_ENVSTAMPRECT lResult: 00000000
<00037> 00020E46 S WM_PSD_PAGESETUPDLG wParam: 00000000 lParam: 00000000
<00038> 00020E46 R WM_PSD_PAGESETUPDLG lResult: 00000002
<00039> 00020E46 S WM_PSD_ENVSTAMPRECT wParam: 00000001 lParam: 00000003 <<<3 of lParam value for WM_PSD_ENVSTAMPRECT
<00040> 00020E46 R WM_PSD_ENVSTAMPRECT lResult: 00000000
<00041> 00020E46 S WM_PSD_PAGESETUPDLG wParam: 00000000 lParam: 00000000


This window WM_PSD_ENVSTAMPRECT function of the value of lParam will update immediately.

I would like to create a globle hook by to monitor the application window WM_PSD_ENVSTAMPRECT in the lParam of the message.

I spent a lot of time to study a lot with the HOOK on the C + + code.

But this problem is too difficult for me.

Difficult to understand.

Please do not give me references.
I've searched a lot of reference material.
I know of are:
1 have to install a hook
2 Select the type of hook
3 defines the structure
4 shared memory should also consider
5 off hook

Install a hook type hook with SetWindowEx do not know what was right.
Define the structure do not know what to consider?

I want to direct this project for me to give me what to write code directly into the help

Thank you.

The following is my code:
-----------------------------------------------

// hookps.cpp : Custom DLL's exported function application.
//
#include <windows.h>
#include "stdafx.h"



 HWND g_hWnd;
 HHOOK hThisHook; //Save the hook handle.
 static LRESULT CALLBACK HookedShellProc(int nCode, WPARAM wParam, LPARAM lParam);
 //Define common data structures
typedef struct
{
 HHOOK hThisHook; //Currently in use HOOK
 //... Increase the sharing of other information here.
};

LRESULT HookProc (
  int code,       // hook code
  WPARAM wParam,  // virtual-key code
  LPARAM lParam   // keystroke-message information
);

HINSTANCE hDll;
BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
)
{
hDll = (HINSTANCE) hModule;
    return TRUE;
};

int GetWindowTextRemote(HWND hwnd,LPSTR lpString)
{
    g_hWnd=hwnd;
    hThisHook=SetWindowsHookEx(WH_SHELL,(HOOKPROC)HookProc,hDll,GetWindowThreadProcessId(hwnd,NULL) );

};

#define RELEASEHOOK(hThisHook)                                                              //  <<<<Off the hook.
{                                  //<<<  I do not know why the smoke has IntelliSense: must be declared.
 if(hThisHook)
  {
   UnhookWindowsHookEx(hThisHook);
   hThisHook = NULL;
  }
};

enum
{
HM_SHELL = 0x0100,
};

--------------------------

# define RELEASEHOOK (hThisHook) / / <<<<<< off the hook
{//<<<
Here do not know why the above has been cropped IntelliSense: The error message must be declared.

This is one of the problems.

Then I now need to add anything in the code or what is wrong or which side of the extra code.

Or where the code is useless at this type of hook in the wrong.

Please give these questions for me to help me.

Dani AI

Generated

Short, practical plan for (and follow‑ups from ): the Page Setup dialog sends PagePaintHook messages such as WM_PSD_ENVSTAMPRECT (WM_USER+5); the lParam you saw is a pointer to a RECT that exists in the dialog process. To observe that RECT from outside, the hook code must run inside the target process (the system injects your hook DLL when you install a thread-specific hook). (learn.microsoft.com)

Which hook to use and how: install a thread-specific hook on the dialog’s thread (use GetWindowThreadProcessId(hwnd, &pid) to get the thread id) and call SetWindowsHookEx from a native C++ DLL. Use WH_CALLWNDPROC to catch messages delivered with SendMessage and WH_GETMESSAGE to catch posted messages (installing both covers both cases). Keep the hook tiny and always call CallNextHookEx. (learn.microsoft.com)

Bitness and privilege gotchas: a 32‑bit DLL can’t be injected into a 64‑bit process (and vice‑versa), so supply matching 32/64‑bit hook DLLs if the target app could be either. Also, UIPI/UAC prevents lower‑integrity processes from injecting into higher ones; hooking an elevated app requires matching privileges or UIAccess rules. Test with the same bitness and integrity level as the target. (learn.microsoft.com)

Forwarding the RECT to your VB.NET host: when the hook runs in the target process it can safely dereference lParam, copy the RECT into a small POD struct, and send it to the VB.NET window with WM_COPYDATA (or use a named pipe / shared mapping if you prefer). Never send raw pointers across processes — use WM_COPYDATA or an IPC channel so the kernel copies the data for you. Minimal example (inside the hook DLL):

extern "C" __declspec(dllexport)
LRESULT CALLBACK CallWndProc(int nCode, WPARAM wParam, LPARAM lParam)
{
    if (nCode >= 0) {
        CWPSTRUCT* p = (CWPSTRUCT*)lParam;
        if (p->message == (WM_USER + 5)) { // WM_PSD_ENVSTAMPRECT
            RECT rc = *(RECT*)p->lParam;   // safe: running in target
            // pack rc into COPYDATASTRUCT and SendMessage(hHostWnd, WM_COPYDATA, (WPARAM)hwnd, (LPARAM)&cds);
        }
    }
    return CallNextHookEx(NULL, nCode, wParam, lParam);
}

References: WMPSD* / PagePaintHook docs, SetWindowsHookEx and Using Hooks, and WM_COPYDATA details. (learn.microsoft.com)

Cautions: export the hook with a plain C export (no C++ name mangling), keep DllMain minimal, avoid heavy work inside the hook, and remove the hook with UnhookWindowsHookEx as soon as you’re done.

Recommended Answers

All 2 Replies

There is an example of setting a windows hook in my skydrive (the link in my signature).

Otherwise, I read your whole post and still don't know what you are wanting.

Sorry, I repeat my clear design of the program.

I use VB.NET to develop a program, but involves third-party software to monitor the control interface.

So I must use C + + to develop a hook.

By creating a dll.

This third-party software to monitor the control interface to send a message to my VB.NET program.

I want to monitor third-party software for this control interface is this:

Then I used SPY + + to view the following information to be:

<00031> 00020E46 S WM_PSD_ENVSTAMPRECT wParam: 00000001 lParam: 00000001 <<<1
<00032> 00020E46 R WM_PSD_ENVSTAMPRECT lResult: 00000000
<00033> 00020E46 S WM_PSD_PAGESETUPDLG wParam: 00000000 lParam: 00000000
<00034> 00020E46 R WM_PSD_PAGESETUPDLG lResult: 00000001
<00035> 00020E46 S WM_PSD_ENVSTAMPRECT wParam: 00000001 lParam: 00000002 <<<2
<00036> 00020E46 R WM_PSD_ENVSTAMPRECT lResult: 00000000
<00037> 00020E46 S WM_PSD_PAGESETUPDLG wParam: 00000000 lParam: 00000000
<00038> 00020E46 R WM_PSD_PAGESETUPDLG lResult: 00000002
<00039> 00020E46 S WM_PSD_ENVSTAMPRECT wParam: 00000001 lParam: 00000003 <<<3 of lParam value for WM_PSD_ENVSTAMPRECT
<00040> 00020E46 R WM_PSD_ENVSTAMPRECT lResult: 00000000
<00041> 00020E46 S WM_PSD_PAGESETUPDLG wParam: 00000000 lParam: 00000000

I have to get the PSD_ENVSTAMPRECT of lParam value of information.

To my VB.NET program.

I have supplemented the program the following concept map to explain my design:

I hope my explanation, make you more clear about my problem.

But I did not experience developed over hook.

A bunch of information on the network but also be hard for me.

Now I need someone to guide me to develop this hook.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.