DllMain

This is a discussion on DllMain within the C Programming forums, part of the General Programming Boards category; Hello everyone, From MSDN, http://msdn2.microsoft.com/en-us/library/ms682583.aspx parameter fdwReason of DllMain has four values, DLL_PROCESS_ATTACH DLL_PROCESS_DETACH DLL_THREAD_ATTACH DLL_THREAD_DETACH I think we could ...

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    DllMain

    Hello everyone,


    From MSDN,

    http://msdn2.microsoft.com/en-us/library/ms682583.aspx

    parameter fdwReason of DllMain has four values,

    DLL_PROCESS_ATTACH
    DLL_PROCESS_DETACH
    DLL_THREAD_ATTACH
    DLL_THREAD_DETACH

    I think we could simply understand what MSDN described about the four values in the following way after some experiment (I have read the big table and want to extract some brief and simple information to understand to remember),

    DLL_PROCESS_ATTACH: will be called only once when the process loads the DLL for the 1st time
    DLL_PROCESS_DETACH: will be called only once when the process unloads the DLL (when process stops)
    DLL_THREAD_ATTACH: will be called every time when a thread inside the current process loads the DLL
    DLL_THREAD_DETACH: will be called every time when a thread inside the current process unloads the DLL

    Is that correct understanding?


    thanks in advance,
    George

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I'm pretty sure that the THREAD_ATTACH/DETACH are when a thread is STARTED and KILLED, rather than when a thread loads the DLL - the latter wouldn't be meaningfull. A DLL will need to know about all threads using the DLL, so that for example thread-local storage can be set up for each DLL.

    It should be pretty easy to test this theory - create a thread in your code, set a breakpoint on DLLmain and see what happens when the thread is created.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Should I export DllMain() function?
    By chiefmonkey in forum Windows Programming
    Replies: 4
    Last Post: 07-12-2009, 06:32 AM
  2. DllMain not being called!
    By Yarin in forum Windows Programming
    Replies: 3
    Last Post: 06-26-2008, 10:06 PM
  3. Delay unloading DLL
    By Elysia in forum Windows Programming
    Replies: 9
    Last Post: 04-30-2008, 05:14 AM
  4. DllMain implementation
    By George2 in forum C++ Programming
    Replies: 48
    Last Post: 02-15-2008, 03:52 AM
  5. Newbie in C++
    By forum_aaa in forum C++ Programming
    Replies: 13
    Last Post: 05-15-2005, 11:01 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21