Hi, all

My question is memory alloc/free in DLL.

in C statements,


if I use above,
what happens?

malloc in attatched processA
malloc in another attatched processB


free processA
fres processB

is that right?

Or, How Can I use that properly?

Posted on 2003-01-23 01:07:12 by muzidowa
Yes, you are right.
Posted on 2003-01-23 15:33:45 by comrade
You should not call C run time functions in DllMain.

according to msdn:

Warning The entry-point function should perform only simple initialization tasks. It must not call the LoadLibrary or LoadLibraryEx function (or a function that calls these functions), because this may create dependency loops in the DLL load order. This can result in a DLL being used before the system has executed its initialization code. Similarly, the entry-point function must not call the FreeLibrary function (or a function that calls FreeLibrary), because this can result in a DLL being used after the system has executed its termination code.

It is safe to call other functions in Kernel32.dll, because this DLL is guaranteed to be loaded in the process address space when the entry-point function is called. It is common for the entry-point function to create synchronization objects such as critical sections and mutexes, and use TLS. Do not call the registry functions, because they are located in Advapi32.dll. If you are dynamically linking with the C run-time library, do not call malloc; instead, call HeapAlloc.
Posted on 2003-01-23 20:42:16 by Mecurius