码迷,mamicode.com
首页 > 其他好文 > 详细

dllmain不能做的事

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

标签:dll   c++   dllmain   c   

首先,参看这篇文章:

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不能做的事

标签:dll   c++   dllmain   c   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!