473,394 Members | 2,063 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

DllMain, DLL_PROCESS_ATTACH, and DLL_PROCESS_DETACH in MFC Extension DLLs

With MFC Extension DLL that exports classes through __declspec(dllexport)

DLL_PROCESS_ATTACH/DLL_PROCESS_DETACH
1. Does each a process loads dll only once and unloads dll only once during
its life-time?

DLL_THREAD_ATTACH/DLL_THREAD_DETACH
2. Does each a thread loads dll only once and unloads dll only once during
its life-time? Does DLL_THREAD_DETACH occurs only when thread terminates?
Thank you,
-Boris
Nov 17 '05 #1
1 8626
Boris wrote:
With MFC Extension DLL that exports classes through
__declspec(dllexport)

DLL_PROCESS_ATTACH/DLL_PROCESS_DETACH
1. Does each a process loads dll only once and unloads dll only once
during its life-time?
If the DLL is statically loaded (i.e. NOT by LoadLibrary), then yes. If the
DLL is loaded by LoadLibrary, it can be loaded and unloadded multiple times.
Since you're exposing classes by __declspec(dllexport), I would expect that
the DLL is statically loaded.
DLL_THREAD_ATTACH/DLL_THREAD_DETACH
2. Does each a thread loads dll only once and unloads dll only once
during its life-time?
DLL_THREAD_ATTACH will be called each time a thread is created. Threads
that existed before the DLL was loaded will never call DLL_THREAD_ATTACH.
For a statically linked DLL, this means that the main thread will never call
thread attach (but it will call process attach).
Does DLL_THREAD_DETACH occurs only when thread
terminates?


DLL_THREAD_DETACH will be called each time a thread other than the main
tread terminates. It may be called on threads for which no
DLL_THREAD_ATTACH call was received. The main thread (or any threadd that
directly calls ExitProcess) will result in a DLL_PROCESS_DETACH call instead
of the thread detach.

-cd
Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: John | last post by:
I tried to search for a solution to this, but I couldn't find one. Maybe I didn't look in the right place, but whatever.... Here is the problem - I have an extension "Myextension" created using...
4
by: Michael Roper | last post by:
In Jesse Liberty's "Programming in C#" he says that "...an assembly must have exactly one entry point: DLLMain, WinMain, or Main. DLLMain is the entry point for DLLs..." In the MSDN ".Net...
7
by: Adam | last post by:
I have a managed cpp wrapper. Im using this in a native dll as a static variable. I need to free this library when the dll is done being used. The perfect place to do this is DllMain for...
3
by: Jozsef Bekes | last post by:
Hi All, is there a mechanism just like DllMain in VC6, a function that gets called whenever an assembly gets loaded? Thank you for all answers. Jozsi
9
by: Ulrich Proeller | last post by:
I currently hunting a problem with a MixedMode dll, which used to work well, until the .NET Framework 2.0 is installed on a machine. Since the, the dll fail when loaded stating that there is a...
2
by: Vincent Fatica | last post by:
I can get Explorer to load (via LoadLibrary()) my DLL using VirtualAlloc(), WriteProcessMemory(), and CreateRemoteThread() (a technique discussed here occasionally). But I'd really like to...
1
by: =?Utf-8?B?U2VhbiBDb25uZXJ5?= | last post by:
Hi, Is it possible to define DllMain in a static library for use in dlls? The reason is that I am defining a platform abstraction for being loaded as a shared library and I figured the simplest...
2
by: -Lost | last post by:
I had the PHP Startup: Unable to load dynamic library 'C:\php\ext\php_json.dll' - The specified module could not be found. I finally figured out the error. The problem is that the DLL relies on...
10
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, From MSDN, http://msdn2.microsoft.com/en-us/library/ms682583.aspx parameter fdwReason of DllMain has four values, DLL_PROCESS_ATTACH
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.