delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2008/10/03/07:02:46

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
To: cygwin AT cygwin DOT com
Date: Fri, 03 Oct 2008 12:00:56 +0100
Subject: non-persistent DllMain
Envelope-To: cygwin AT cygwin DOT com
Message-ID: <48E5FB68.1090104@liddicott.com>
From: "Sam Liddicott" <sam AT liddicott DOT com>
User-Agent: Thunderbird 2.0.0.17 (X11/20080925)
MIME-Version: 1.0
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.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

I'm trying to use the Win32::GuiTest perl module on WinXP SP3.
I installed it under cygwin with something like:

perl -MCPAN -e 'install Win32::GuiTest'

However certain use is failing on the SetWindowHookEx because it is
passing a NULL hModule, which is surprising because dllmain shows that
hModule is saved in g_hDLL - except it's not working like that.

BOOL APIENTRY DllMain(HANDLE hModule, DWORD  ul_reason_for_call,
                      LPVOID lpReserved)
{
        switch (ul_reason_for_call)
        {
        case DLL_PROCESS_ATTACH:
                // Value used by SetWindowsHookEx, etc.
                g_hDLL = (HINSTANCE)hModule;
                break;
        case DLL_THREAD_ATTACH:
        case DLL_THREAD_DETACH:
        case DLL_PROCESS_DETACH:
                break;
        }

        return TRUE;
}

g_hDLL is always 0.

If I put in DllMain
if (! hModule) return FALSE;
then the load does NOT abort like a plain return FALSE, so I know
hModule is passed in as non-zero

Further debugging shows the following:

return FALSE; aborts the program - the only debugging tool that works,
because:

setting global variables in DllMain has no effect, when examined later
in the DLL, they have their default initialized values. Even variables
that don't have a specific initialized don't retain any value set during
DllMain

calling functions like fprintf, fopen have no effect in DllMain, not
even strace shows up their attempted use. Not even setenv does anything
in DllMain.

So, in short, DllMain doesn't save the hModule because it can't save
global variables, in fact it seems so ephemeral that the only thing it
CAN do is: return FALSE or return TRUE.

Anyone recognize this problem or have suggestions on what to do?

Sam

--
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