This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: non-persistent DllMain


[sent again without optional alternative html part]

* Dave Korn wrote, On 03/10/08 13:34:
> 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)."
>   
Yep, you are quite right. I just changed this to
GetModuleHandle("GuiTest.dll"); and it no longer crashes - the hookproc
still isn't called though :-(
> ... 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?
>   
it's hard to tell, it's explorer.exe that is crashing.
>   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.
>   
Thanks, I was wondering how to get at the OutputDebugMessage text. I've
been out of windows dev for a long time.
I'll see if hModule is the same as GetModuleHandle(dllname); and if so
I'll look at why the hookproc isn't being called.
I don't know if I have the skill to work out why dllmain won't hold
global vars, but I can debug what is going on.

The top of source is here, should you feel inclined to peep:
http://cygwin.pastebin.com/m410a886a

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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]