Page 1 of 1

SetWindowsHookExA

Posted: Fri Jul 09, 2004 2:19 pm
by shadowstar

Code: Select all

HHOOK
WINAPI SetWindowsHookExCallback(
    int idHook,
    HOOKPROC lpfn,
    HINSTANCE hMod,
    DWORD dwThreadId
    )
{
    char AppName[MAX_PATH];
    char DllName[MAX_PATH];

    if (GetModuleFileName(NULL, AppName, MAX_PATH) > 0
        && GetModuleFileName(hMod, DllName, MAX_PATH) > 0)
    {
        char HookText[1024];

        sprintf(HookText,
            "AppName: \"%s\",\n"
            "DllName: \"%s\".\n"
            "Is this hooking allowed?",
            AppName,
            DllName);
        if (MessageBox(
            NULL,
            HookText,
            "Warning",
            MB_ICONWARNING | MB_YESNO
            ) == ID_NO)
        {
            ::SetLastError(ERROR_ACCESS_DENIED);
            return NULL;
        }
    }
    
    return SetWindowsHookExNext(
        idHook,
        lpfn,
        hMod,
        dwThreadId
        );
}
The MessageBox can not be closed.

Posted: Sun Jul 11, 2004 7:31 am
by madshi
I can't say why this happens. Maybe the program which calls SetWindowsHookEx behaves somehow strangely and thus doesn't like the MessageBox call at all. Is it your own program which calls SetWindowsHookEx?

I suggest sending an IPC message to your application and let that show a message box and return the result back to the hook dll. You can see how that works in the HookProcessTermination demo.

can't hook the SetWindowsHookExA that was called by my DLL

Posted: Sat Jul 24, 2004 8:06 am
by shadowstar
can't hook the SetWindowsHookExA that was called by my DLL

Star.exe
|
v
Shadow.dll -> EnableHook -> SetWindowsHookExA

Posted: Tue Jul 27, 2004 7:29 am
by shadowstar
Can't create VCL form when handle Ipc message request.

Code: Select all

procedure HandleProcessTerminationRequest(name       : pchar;
                                          messageBuf : pointer;
                                          messageLen : dword;
                                          answerBuf  : pointer;
                                          answerLen  : dword); stdcall;
// this function is called by the ipc message whenever our dll contacts us
var s1, s2, s3 : string;
      Form1: TForm1;
begin
  Form1 := TForm1.Create(Application); // Process stop response on this line
...

Posted: Wed Jul 28, 2004 6:56 am
by madshi
I don't have the overview about what you're doing exactly. If you can create a small demo (please as small as possible) which reproduces the problems, I might have a look at it to see what's wrong.