delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2008/10/03/08:35:38

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
From: "Dave Korn" <dave DOT korn AT artimi DOT com>
To: <cygwin AT cygwin DOT com>
References: <48E5FB68 DOT 1090104 AT liddicott DOT com> <48E5FE38 DOT 7040400 AT gmail DOT com> <48E60C19 DOT 8070409 AT liddicott DOT com>
Subject: RE: non-persistent DllMain
Date: Fri, 3 Oct 2008 13:34:55 +0100
Message-ID: <028e01c92554$709fef20$9601a8c0@CAM.ARTIMI.COM>
MIME-Version: 1.0
X-Mailer: Microsoft Office Outlook 11
In-Reply-To: <48E60C19.8070409@liddicott.com>
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id m93CZbYE022601

Sam Liddicott wrote on 03 October 2008 13:12:

> [Forgot to copy this to the list, + new question]
> 
> * Aurimas Černius wrote, On 03/10/08 12:12:
>> If I'm not wrong, GetModuleHandle(NULL) returns the handle of the
>> current module (should be DLL handle, when called from DLL). So saving
>> handle to a global variable is not needed.
>> 
> thanks!

  GetModuleHandle will return the main .exe's handle, won't it?  MSDN says:

http://msdn.microsoft.com/en-us/library/ms683199(VS.85).aspx
"If this parameter is NULL, GetModuleHandle returns a handle to the file used
to create the calling process (.exe file)."

... and I have a memory that this issue cropped up recently in the context of
the cygwin dll's DllMain call.

>> I think that DllMain is called when DLL is not yet completely loaded,
>> so it is impossible to set values of global variables. Isn't it?
>> 
> Makes sense, 

  No it doesn't.  The DLL is completely loaded and all relocations applied.
Anything else would be insanity.

> Sadly it then crashes explorer.exe, but thats another problem for me to
> look into.

  No, it's because you haven't solved the underlying problem yet.

> It crashes when I do the first sendmessage after hooking.

... with presumably a null pointer dereference?

  DllMain is special.  There's a lot you cannot do in there, in particular
file i/o, printf etc, because you're running inside a lock and it's a sort of
critical section-y sort of situation, and indeed the MSVC CRT probably isn't
inited yet, so you definitely won't have stdio.

  If I were you, I'd put loads of OutputDebugMessage calls in your DllMain,
and watch what's happening and look at the value of hModule, and the addressof
g_hDLL (etc) using Sysinternals DebugView.



    cheers,
      DaveK
-- 
Can't think of a witty .sigline today....


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019