一句话总结:DllMain函数是dll的entry point。但是,有两种dll可以不用带dllmain函数:一种自然是资源dll;另一种是dll不需要在entry point做什么事情,所以不写了干脆。但是系统在往进程里加载一个dll的时候,一定会去找dllmain的。如果dll本身没有提供,那么会调用一个默认的(应该是CRT的)dllmain函数。
MSDN上的话:
DllMain Callback Function
An optional entry point into a dynamic-link library (DLL). When the system starts or terminates a process or thread, it calls the entry-point function for each loaded DLL using the first thread of the process. The system also calls the entry-point function for a DLL when it is loaded or unloaded using the LoadLibrary and FreeLibrary functions.