.NET Forms application using ATL always crashes RRS feed

  • Question

  • Hi,

    I'd like to use OLE from within a .NET Forms application. When adding
    #include <atlbase.h>
    #include <atlcomcli.h>
    to "stdafx.h" I am still able to compile the Forms application. But as soon as I start the application it crashes. In the project properties I set
    "use of ATL" to "Static Link to ATL"
    "Common Language Runtime Support" to "Common Language Runtime Support (/clr)".

    In debug mode the following message shows:

    Debug Assertion Failed!
    Program: ...ien\VisualStudio2008\Projects\OOLibrary\Debug\OOLibrary.exe File: f: \dd\vctools\crt_bld\self_x86\crt\src\dbgheap. c Line: 1511
    Expression: _CrtIsValidHeapPointer(pUserData)
    For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts.
    (Press Retry to debug the application)

    What is wrong here?


    Saturday, February 6, 2010 7:52 PM


All replies

  • An invalid pointer is being passed to heap functions. 

    (Press Retry to debug the application.) 

    Then examine the debugger stack window, which shows where in your code the problem started.
    Saturday, February 6, 2010 10:02 PM
  • I don't use any functions or objects of ATL so far. According to the calling stack, this is the highest function level I can see. It's in "mstartup.cpp" Everything above is assembly language only.

    * .cctor - This is global constructor for user module.
    * Purpose:
    *       This function is called during appdomain creation. Here is we
    *       initialize all the vtables, and native/process/appdomain variables.
    * Exit:
    * Entry:
    void __clrcall __identifier(".cctor")()
        using namespace __identifier("<CrtImplementationDetails>");
        LanguageSupport languageSupport;
        languageSupport.Initialize();  // <<< the error is within this function call

    And this is where the assertion happens (in file "dbgheap.c"):

    * If this ASSERT fails, a bad pointer has been passed in. It may be
    * totally bogus, or it may have been allocated from another heap.
    * The pointer MUST come from the 'local' heap.
    _ASSERTE(_CrtIsValidHeapPointer(pUserData)); // <<<<<< pUserData is 0xb6c2e9c9

    It's outside my own code. It must be something in the compiler generated startup code. Maybe a conflict between CLI and ATL initialization?
    I only added the two mentioned header files. That was all.
    Sunday, February 7, 2010 8:06 AM
  • You would like to take a look at these links:
    Problem with C++/CLI + ATL Combo
    Error when <atlbase.h> included in wizard generated Windows Form App

    To use ATL in CLI form project, the workaround is:

    >>Quote from Problem with C++/CLI + ATL Combo
    "add __DllMainCRTStartup@12 to the Force Symbol References item in the Linker/Input section of the project settings."

    Wesley Yao [MSFT]
    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact: msdnmg @ microsoft.com
    Please mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by wannabe_2 Monday, February 8, 2010 5:00 PM
    Monday, February 8, 2010 8:55 AM
  • Many thanks Wesley,

    you saved my day.

    Monday, February 8, 2010 5:14 PM