Prepare the MFC DLL for Use

OverviewHow Do IDetails

To prepare the MFC DLL for use

  1. Add code to the starter code generated by AppWizard.

  2. Make sure you have exported the entry points to your DLL by using either the __declspec(dllexport) keyword 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.

  3. Prepare a header (.H) file to include in the programs using your DLL. This header file must contain the declarations of the exported functions and/or exported C++ classes. Use the __declspec(dllimport) keyword on the declarations of the exported functions and C++ classes in this header file. The compiler produces more efficient code with __declspec(dllimport). See on exporting functions and classes from an MFC DLL.

  4. Build the DLL.

  5. If applications will be linking to your DLL implicitly, provide an import library for the applications to link to.

When you build your DLL, the linker also builds an import library for you. This library has the same base name as your DLL, but has the extension .LIB. You may want to provide both a debug and retail (/release) version of your DLL. This permits client programs to build both debug and retail versions of their applications and link them with the appropriate debug or retail version of all DLLs.

If you are building an application that implicitly links to a DLL, add the import library to the Object/library modules text box on the Link tab in the Project Settings dialog box. Make sure you put the debug version of the import library in the debug settings and the release version in the release settings. The only other change you must make is to add the include file for the DLL to any source files that call the DLL’s exported functions.

What do you want to do?