Re: Multiple instances of DLL in memory.

From: Peter Below (TeamB) (100113.1101_at_compuXXserve.com)
Date: 11/28/03


Date: Fri, 28 Nov 2003 19:57:04 +0100

In article <3fc76f93@newsgroups.borland.com>, Ihor Bobak wrote:
> I created a dll which sets a global WH_SHELL hook,
> and .exe which uses this dll.
>
> This dll sends messages to a window in my .exe when
> the global hook procedure is called by some process.
>
> The problem is next: this dll is loaded for each process
> separately. Process Viewer shows 10 or more copies of my
> dll in memory (used by each process which called my
> hook procedure).
>
> I cannot understand why my dll is not loaded just once?
> I saw many examples (written on C++) which set the
> same hook in the same way, but their dll is loaded
> only once and used by many processes simultaneously.

A hook DLL is always loaded into each running process, regardless of
what it has been written in. The OS will share the code pages between
processes but not the data pages, unless they have been marked as
shared memory. The Delphi linker does not support this but VC++ does,
for example.

--
Peter Below (TeamB)  
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be


Relevant Pages

  • Hooking exit process
    ... As a continuation of my other thread here, I am now trying to hook ... ExitProcess() so a routine up in my dll will be called at the time the exe ... So I pasted the code in to my dll and MyExitProcessis never called. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Using Visual Basic to Write System-Wide Hooks
    ... >I've spent about an hour looking into writing a system-wide hook using only ... a system-wide callback function must be located within a DLL. ... >system-wide hook DLL. ... The reason is that Visual Basic has some large runtime ...
    (microsoft.public.vb.winapi)
  • Re: Preventing a program from gaining the focus with a CBT hook
    ... Giving focus back to the losing window... ... Hooks being intrusive / DLL unload issues... ... Why not "memset(caption, 0, sizeof(caption))"? ... It is easy to forget how utterly intrusive a system hook is. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: SetWindowsHookEx
    ... automatically inject into all programs. ... It sets the global hook on the ... DLL injecting - in all likelyhook SetWindowsHook returns before the DLL has ... with your shared-section, then the gHook variable (which contains ...
    (microsoft.public.vc.language)
  • shared dll in hook
    ... so below is my shared memory part of the DLL in which i run a WH_CBT hook ... and subclass another apps windows. ...
    (microsoft.public.vc.language)