的DllMain [英] DllMain

查看:70
本文介绍了的DllMain的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

来自MSDN,

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


参数fdw DllMain的原因有四个值,


DLL_PROCESS_ATTACH

DLL_PROCESS_DETACH

DLL_THREAD_ATTACH

DLL_THREAD_DETACH


我想我们可以通过一些实验(以下读大表和

)以下列方式简单了解MSDN对四个值

的描述。想要提取一些简单而简单的信息来理解记住),


DLL_PROCESS_ATTACH:当进程加载DLL时只调用一次

为第1个时间

DLL_PROCESS_DETACH:当进程卸载

DLL时(进程停止时)将只调用一次

DLL_THREAD_ATTACH:每次调用当一个线程里面的

当前进程加载DLL

DLL_THREAD_DETACH:每次当

当前进程内的线程卸载DLL时都会调用


这是正确的理解吗?

提前感谢,

George

解决方案

>这是正确的理解吗?


是的,基本上就是这样 - 当然我最好的理解。


Dave


George,

当创建新的
线程时,将为每个已加载的DLL调用DLL_THREAD_ATTACH。 (这允许DLL设置线程本地

存储空间)。线程不需要加载DLL。类似地,对于DLL_THREAD_DETACH,
- 当线程退出时,每个加载的DLL都被调用。

Bob


" George" < Ge **** @ discussion.microsoft.com写信息

news:92 ************************ ********** @ microsof t.com ...


大家好,


来自MSDN,



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

参数fdw DllMain的原因有四个值,


DLL_PROCESS_ATTACH

DLL_PROCESS_DETACH

DLL_THREAD_ATTACH

DLL_THREAD_DETACH


我想我们可以简单地理解MSDN所描述的内容经过一些实验后,以下方式讨论了四个价值的b $ b价值

(我已经阅读了大表格和

想要提取一些简单而简单的内容要理解的信息

记住),


DLL_PROCESS_ATTACH:当进程加载

DLL时,将只调用一次/>
第一次

DLL_PROCESS_DETACH:当进程卸载

DLL时(进程停止时)将只调用一次

DLL_THREAD_ATTACH:每次调用一个线程时都会调用

当前进程加载DLL

DLL_THREAD_DETACH:每次当

当前进程内的线程卸载DLL时都会调用它>

这是正确的理解吗?


提前感谢,

George





" George" < Ge **** @ discussion.microsoft.com写信息

news:92 ************************ ********** @ microsof t.com ...


大家好,


来自MSDN,



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

参数fdw DllMain的原因有四个值,


DLL_PROCESS_ATTACH

DLL_PROCESS_DETACH

DLL_THREAD_ATTACH

DLL_THREAD_DETACH


我想我们可以简单地理解MSDN所描述的内容经过一些实验后,以下方式讨论了四个价值的b $ b价值

(我已经阅读了大表格和

想要提取一些简单而简单的内容要理解的信息

记住),


DLL_PROCESS_ATTACH:当进程加载

DLL时,将只调用一次/>
第一次

DLL_PROCESS_DETACH:当进程卸载

DLL时(进程停止时)将只调用一次



否,这些是错误的(其他人解释了THREAD消息)。


如果使用LoadLibrary和FreeLibrary,则每次使用计数从0变为DLL_PROCESS_ATTACH时都会调用

每次使用次数从1变为0时,将1和DLL_PROCESS_DETACH称为

。这可能会在一次运行中发生多次

次。


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

解决方案

>Is that correct understanding?

Yes that''s essentially it - to the best of my understanding of course.

Dave


George,
DLL_THREAD_ATTACH will be called for every already loaded DLL when a new
thread is created. (This allows the DLL to setup things like thread local
storage). There is no requirement for the thread to load the DLL. Similarly
for DLL_THREAD_DETACH - every loaded DLL is called when the thread exits.
Bob

"George" <Ge****@discussions.microsoft.comwrote in message
news:92**********************************@microsof t.com...

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




"George" <Ge****@discussions.microsoft.comwrote in message
news:92**********************************@microsof t.com...

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)

No, these are wrong (others have explained the THREAD messages).

If LoadLibrary and FreeLibrary are used, then DLL_PROCESS_ATTACH is called
each time the use count changes from 0 to 1 and DLL_PROCESS_DETACH is called
each time the use count changes from 1 to 0. This could happen multiple
times in a single run.


这篇关于的DllMain的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆