ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • MSVCRTD.dll 충돌
    Window Programming/MFC 2008. 10. 30. 00:22
    728x90

    [출처] _CrtIsValidHeapPointer 에러|작성자 형기


    Visual C++과 STL을 이용한 dll을 만들 경우
    std::string 사용시 _CrtIsValidHeapPointer 에러가 발생하는 경우가 있습니다.
    원인은 MS에서 제공하는 C Runtime Library (msvcrt.dll, msvcr70.dll, msvcr71.dll 등)의 버전을 다르게 쓰고있기 때문입니다.
    C Runtime Library의 버전에 따라서 CRT State와 Heap, file등의 정보를 같이쓰고 있어서 충돌이 생긴경우입니다.

     

    이 경우는 프로젝트 전체에서 CRT dll을 사용하게 하든지, 아니면 각각의 crt상태를 가질 수 있도록 수정하여야 합니다.  

    간단히는 빌드옵션에서 /MD, /MDd를 사용해서 해결합니다.
    (각각의 CRT state를 가질 수 있도록 합니다.)
    /MD: 다중 쓰레드 DLL (우리가 만드는 dll에서 msvcr71.dll과 msvcp71.dll을 사용)
    /MDd: 다중 쓰레드 디버그 DLL (우리가 만드는 dll에서 msvcr71d.dll과 msvcp71d.dll을 사용)

     원문:

    You need to link these modules to the same CRT DLL to have any hope of
    passing C++ objects between modules. This will cause the modules to share
    the same CRT state, including heap, file descriptors, errno, locale, etc. If
    you don't do this, each module will have its own private copy of the CRT
    state, and you won't be able to do things such as allocate memory in one
    module and free it in another.

    At the command line, see the /MD and /MDd options; as you're using the C++
    Standard Library, they will cause you to link to both the C and C++ RT DLLs
    (e.g. msvcr71.dll and msvcp71.dll for VC 7.1 release builds).

    In the VC6 IDE, verify that in the Project Settings C/C++ tab, category
    "Code Generation", "Use run-time library" is  set to "Debug Multithreaded
    DLL" for debug builds and "Multithreaded  DLL" for release builds. If you're
    using MFC, also select "Use MFC as a shared DLL".

    In the VC.NET IDE, verify that in the project's Property Pages,
    "Configuration Properties | C/C++ | Code Generation | Runtime Library" is
    set to "Multi-threaded DLL" for release builds and "Multi-threaded Debug
    DLL" for debug builds. In "Configuration Properties | General", make sure
    "Use of MFC" and "Use of ATL" are consistent with the RTL settings.

    ==========================

    1. Have everyone link to the same CRT DLL (e.g. msvcrt.dll or
    msvcrtd.dll). This causes the dynamically linked components to share
    the same heap and other CRT state, such as file descriptors, so the
    whole acts like one statically linked C or C++ program, one module can
    release a resource acquired by another, and your sanity is preserved.
    2. Ensure that only the module which allocates a resource such as
    memory or a file descriptor frees it. This typically means creating
    various create_resource/free_resource functions in each module.

    In general, (1) is by far the preferable alternative.


    프로젝트 진행시 MFC 동적 DLL연결을 정적 라이브러리 연결로 변경할때 dll충돌이 발생했다. 그래서 빌드옵션을 /MD, /MDd 로 변경하고 stdafx.h에서 #define _AFXDLL 를 추가하니 문제가 해결!!

    비슷한 문제를 설명한 링크
    http://cafe.naver.com/jzsdn.cafe?iframe_url=/ArticleRead.nhn%3Farticleid=13934
    http://www.devpia.com/MAEUL/Contents/Detail.aspx?BoardID=50&MAEULNo=20&no=657122&ref=657122

    'Window Programming > MFC' 카테고리의 다른 글

    CTreeCtrl검색 및 선택  (2) 2008.12.08
    mfc42u.lib문제 - (unicode library)  (0) 2008.12.01
    콤보박스리스트조절  (0) 2008.10.05
    title name변경  (0) 2008.10.05
    Window I/O 제어  (0) 2008.03.21

    댓글

Designed by black7375.