Linking Your Application to the MFC for Windows CE Libraries

You can use the MFC library for Windows CE either as a statically linked library or as a DLL. When you use MFC as a statically linked library, the MFC code is included in your executable the same way C functions are linked in when you use a standard C library. When you use MFC as a DLL, the MFC library is loaded at run-time, and the same DLL can be shared by multiple applications.

Using MFC as a shared DLL generates smaller applications. When developing for desktop Windows platfroms, if you you use MFC as a DLL, you have to include the MFC DLL when you ship your application. Many Windows CE devices, however, include the MFC DLLs in ROM.

In the Microsoft Foundation Class library for desktop platforms, the core classes and the OLE support classes are combined in the same dynamic link library (DLL). In MFC for Windows CE, the OLE support classes are contained in a separate DLL, called Olece20.dll. This helps conserve memory resources. If you're not using the OLE/ActiveX classes, they don't have to be loaded into memory. This also gives Windows CE device manufacturers more flexibility, becaue they can choose to support MFC for Windows CE, either with or without the OLE/ActiveX classes.

MFC for Windows CE supports the following four kinds of DLLs.

To use the Windows CE MFC library as a shared DLL, your application must be linked with the following libraries.

Mfcce20.lib Export library for linking against Mfcce20.dll
Mfcs42.lib Static "helper" library for Mfcce20.dll
Olece20.lib Export library for linking against Olece20.dll

When you use the Windows CE MFC library as a shared DLL, define _AFXDLL in your preprocessor definitions. This will cause your project to be linked with the Mfcce20.lib export library and the Mfcs42.lib static helper library. If your project supports ActiveX, it will also be linked with the Olece20.lib export library.

When you use the Windows CE MFC library as a statically linked library,do not define _AFXDLL. If _AFXDLL is not defined, your project will be linked with the static MFC library, uafxwce.lib.

If your project is an ActiveX control, you must include afxctl.h in your stdafx file. (The stdafx.h file is used to build precompiled headers, and is generated by the ClassWizard.) If your project is an ActiveX container, you must include afxdisp.h in your stdafx.h file, and call the AfxEnableControlContainer initialization function in the InitInstance method of your CWinApp derived class.

When you use the WCE MFC AppWizard to create an application or DLL, the AppWizard automatically specifies the compile and link settings that the linker uses to link your application to the appropriate MFC libraries. The AppWizard also includes the appropriate ActiveX header files in your project, if required.