PRB: L2025 with a CWinApp-Derived Class in an Extension DLL

Last reviewed: July 18, 1997
Article ID: Q117564
7.00 | 1.00 1.50 MS-DOS | WINDOWS kbprg kbprb

The information in this article applies to:

  • The Microsoft Foundation Classes (MFC), included with:

        - Microsoft C/C++ version 7.0
        - Microsoft Visual C++ for Windows, versions 1.0 and 1.5
    

SYMPTOMS

It can be useful to define and export (not necessarily instantiate) a CWinApp-derived class within an MFC-extension DLL (_AFXDLL defined). However, the linker generates the following:

   d:\msvc\mfc\lib\mfc250d.lib(dumpout.cpp) : error L2025: _AfxTrace :
       symbol defined more than once
   d:\msvc\mfc\lib\mfc250d.lib(afxmem.cpp) : error L2025: void __far* __far
       __cdecl operator new(unsigned int) : symbol defined more than once
   d:\msvc\mfc\lib\mfc250d.lib(afxmem.cpp) : error L2025: void __far* __far
       __cdecl operator new(unsigned int,char const __far*,int) : symbol
       defined more than once
   d:\msvc\mfc\lib\mfc250d.lib(afxmem.cpp) : error L2025: void __far
       __cdecl operator delete(void __far*) : symbol defined more than
       once
   d:\msvc\mfc\lib\mfc250d.lib(afxmem.cpp) : error L2025: public: static
       void __far* __far __cdecl CObject::operator new(unsigned int) :
       symbol defined more than once
   d:\msvc\mfc\lib\mfc250d.lib(afxmem.cpp) : error L2025: public: static
       void __far* __far __cdecl CObject::operator new(unsigned int,char
       const __far*,int) : symbol defined more than once
   d:\msvc\mfc\lib\mfc250d.lib(afxmem.cpp) : error L2025: public: static
       void __far __cdecl CObject::operator delete(void __far*) : symbol
       defined more than once
   d:\msvc\lib\ldllcew.lib(fmalloc.asm) : error L2025: __fmalloc : symbol
       defined more than once
   d:\msvc\lib\ldllcew.lib(fmalloc.asm) : error L2025: __ffree : symbol
       defined more than once

CAUSE

The CWinApp::_ForceLinkage member function of the CWinApp class forces the routines mentioned in the error messages to be linked in from the file DLLINIT.CPP. This member function is used only by the MFC libraries. Having these routines defined in DLLINIT.CPP as well as in the class libraries causes the error message "symbol defined more than once".

The _fmalloc, _free, new, and delete errors can also be caused by a call to AfxCheckMemory() in a MFC extention DLL. This problem can occur with or without a CWinApp derived class.

RESOLUTION

To work around the problem, override CWinApp::_ForceLinkage(). The function should do nothing, but it prevents the base class function from linking in the DLLINIT.CPP file.

This is not a problem with Visual C++ 32-bit Edition, because there is no CWinApp::_ForceLinkage. Calling AfxCheckMemory() is also safe from a 32-bit extension DLL.

MORE INFORMATION

The following sample code is an example of a CWinApp-derived class that might be included in an _AFXDLL DLL with a _ForceLinkage() member declaration:

Sample Code

/* Compile options needed: /D_AFXDLL
*/

   class CMyApp: public CWinApp
   {
    ...
        void _ForceLinkage()
        {
        #ifndef _WINDLL
          CWinApp::_ForceLinkage();
        #endif
        }
    ...
   };


Additional reference words: 7.00 1.00 1.50 2.00 2.50
KBCategory: kbprg kbprb
KBSubcategory: MfcDLL
Keywords : kb16bitonly MfcDLL kbprb kbprg
Technology : kbMfc
Version : 7.00 | 1.00 1.50
Platform : MS-DOS WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 18, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.