Initializing Non-MFC DLLs

 

The latest version of this topic can be found at Initializing Non-MFC DLLs.

To initialize non-MFC DLLs, your DLL source code must contain a function called DllMain. The following code presents a basic skeleton showing what the definition of DllMain might look like:

BOOL APIENTRY DllMain(HANDLE hModule,   
                      DWORD  ul_reason_for_call,   
                      LPVOID lpReserved)  
{  
    switch( ul_reason_for_call ) {  
    case DLL_PROCESS_ATTACH:  
    ...  
    case DLL_THREAD_ATTACH:  
    ...  
    case DLL_THREAD_DETACH:  
    ...  
    case DLL_PROCESS_DETACH:  
    ...  
    }  
    return TRUE;  
}  

Note

The Windows SDK documentation for DllEntryPoint says that the actual name of the entry-point function must be specified on the linker command-line with the /ENTRY option. With Visual C++, you do not need to use the /ENTRY option if the name of your entry-point function is DllMain. In fact, if you do use the /ENTRY option and name your entry-point function something other than DllMain, the C run-time library will not get initialized properly.

What do you want to know more about?

See Also

Initializing a DLL