Calling the C Run-Time Library from a DLL

When linking a DLL with any of the C run-time libraries, you must specify the following the entry point for the DLL.

-entry:_DllMainCRTStartup$(DLLENTRY)

This entry point is exported from the C run-time libraries and performs necessary initialization. The $(DLLFLAGS) macro in WIN32.MAK includes the -entry flag shown above.

DllMainCRTStartup will call your entry point if you name it DllMain and export it from your DLL. Therefore, your DLL entry-point function will look something like this:

BOOL WINAPI DllMain( HINSTANCE hinstDLL, 
                     DWORD fdwReason,
                     LPVOID lpReserved )
{

   if( fdwReason==DLL_PROCESS_ATTACH || fdwReason==DLL_THREAD_ATTACH )
   ...
   if( fdwReason==DLL_PROCESS_DETACH || fdwReason==DLL_THREAD_DETACH )
   ...

   return( TRUE );

}

For more information, see DllMain.