首页 > 其他 > 详细

dllmain不能做的事

时间:2015-02-12 02:03:28      阅读:271      评论:0      收藏:0      [点我收藏+]

首先,参看这篇文章:

http://msdn.microsoft.com/en-us/library/windows/desktop/dn633971%28v=vs.85%29.aspx


loadlibrary时,会先加锁,然后调用dllmain,然后解锁返回。

所以dllmain中,要做的初始化或清理越简单越好。该做的复杂的初始化,应该延迟,在loadlibrary之后。


不能做的事:

LoadLibrary 

CreateThread

CreateProcess

GetModuleFileName

就是少用Windows API。


Use the memory management function from the dynamic C Run-Time (CRT) ? 这个是指什么


如果一定要在其中初始化,可以这样异步:

One of the approaches I’ve used has been to make use of Win32 asynchronous procedure calls. Specifically you can call QueueUserAPC to add a function to the queue, and this can contain the initialisation you would’ve otherwise done in DllMain.

However there is significant gotcha regarding use of APCs: your function will not be called until the thread is in an “alertable wait state”. This means you (or some other code on the thread) need to call an alertable wait function such as SleepEx, WaitForSingleObjectEx and specify TRUE for the alertable parameter.


本文出自 “v” 博客,请务必保留此出处http://4651077.blog.51cto.com/4641077/1613810

dllmain不能做的事

原文:http://4651077.blog.51cto.com/4641077/1613810

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!