次の方法で共有


Build Settings for an MFC DLL

OverviewHow Do IDetails

The project settings that the MFC AppWizard (DLL version) sets for DLLs are almost the same as for the MFC AppWizard (EXE version). The following table describes the compiler options and preprocessor defines that the MFC AppWizard sets that distinguishes DLLs from EXEs and distinguishes each kind of MFC DLL from each other.

Kind of DLL Compiler options Preprocessor defines
Regular, statically linked to MFC /MT or /MTd _WINDLL
_USRDLL
Regular, using the shared MFC DLL /ML or /MLd _WINDLL
_USRDLL
_AFXDLL
Extension DLL /MD or /MDd _WINDLL
_AFXDLL
_AFXEXT

The preprocessor defines identify the kind of MFC DLL that you are building. The /MD, /MT, and /ML options determine whether the DLL being built has single-thread support (/MD), multithread support (/MT), or uses the shared MFC DLL (/ML) option.

It is usually best to use the MFC AppWizard (DLL version) default option /MD or /MT when building a DLL. These options support multithread applications. When you specify the /ML option, your DLL will work only when called by single-thread applications. A multithread application that calls a DLL without multithread awareness is likely to fail. Therefore, don’t specify the /ML option unless you know that it will be used only by single-thread applications.

The MFC AppWizard (DLL version) sets the Link option /DLL for all three kinds of MFC DLLs. The /DLL option causes the linker to build a DLL and do the following:

  • Look for the DllMain function in the source code.

  • Link with DLL startup code that performs some initialization for you.

  • Produce an import library for applications using your DLL to link with.

Note that the MFC AppWizard (DLL version) does not set the /DEF option; this option is for use only on the command line. If a .DEF has been added to the project, the linker will use it automatically.

What do you want to do?