Share via


Add Code to the MFC DLL Starter Files

OverviewHow Do IDetails

If your DLL needs initialization or termination code, where you add that code depends on the kind of DLL that you have created.

For extension DLLs, the .CPP file that AppWizard creates contains the function DllMain. Any initialization or termination code for your DLL should be added to this function.

For regular DLLs, initialization code should be added to the InitInstance member function of the application-derived CWinApp class. Termination code should be added to ExitInstance.

Add the rest of your code to either the .CPP file created by AppWizard or create new source files and add them to the project. Make sure you have exported the entry points to your DLL by using either the keyword __declspec(dllexport) or by listing the functions in the DLL’s .DEF file. If exporting C++ classes, you may want to use the AFX_EXT_CLASS macro.

The easiest way to add functions and navigate to them in your starter files is by using either ClassWizard or WizardBar.

What do you want to do?