Need some help with my program MFC

Posted on 2009-02-18
Last Modified: 2013-11-20
my SDI runs fine. When I close it I get a stop afxtls.cpp (see below)
What kind of error is this?
Please help.
500 poinst.
Best regards,


inline void* CThreadSlotData::GetThreadValue(int nSlot)



	ASSERT(nSlot != 0 && nSlot < m_nMax);

	ASSERT(m_pSlotData != NULL);

	ASSERT(m_pSlotData[nSlot].dwFlags & SLOT_USED);

	ASSERT(m_tlsIndex != (DWORD)-1);

	if( nSlot <= 0 || nSlot >= m_nMax ) // check for retail builds.



		return NULL;<---------------------------------------stops here


Open in new window

Question by:tsp2002
    LVL 19

    Expert Comment

    Have you more then 1 thread?
    Do you terminate all the thread correctly before exit the application?

    Author Comment

    Have you more then 1 thread? what does that mean?
    LVL 19

    Expert Comment

    Does your application create any worker thread?

    Author Comment

    I jused used button project clean
    and project rebuild before I started with debug button.
    (the button names could be different at your version)
    Now the error is gone???
    I don´t know why.
    Does your application create any worker thread?What is a thread??? sorry
    LVL 19

    Expert Comment

    If you don't know what a thread is, you couldn't create one...    ;-)

    For more informations give a look at
    LVL 39

    Accepted Solution

    >>>> Does your application create any worker thread?

    The CThreadSlotData class in MFC was used for single threaded applications as well.

    IMO, the error has nothing to do with threads. The assertion most probably came because of a precompiled headerfile which was out-of-date. Then, any of the members m_sect, m_nMax or m_tlsIndex got corrupt and you got an assertion.

    a thread is own branch of execution in a process. Each process has at least one thread, the main thread. You can by code create a second (or more) thread which would asynchronously run parallel to the main thread, e. g. to make a calculation or read an imgae from a file, or similar. If you create a thread you pass a function with the thread which then was executed.

    an assertion is a statement which breaks in the debugger if the condition in the argument was false:

       ASSERT(nSlot != 0 && nSlot < m_nMax);

    would bring an error and break in the debugger if either the argument nSlot is 0 or if nSlot is greater or equal to m_nMax (what is a member of the class CThreadSlotData). Such assertions are a means to program a precondition for a function. It normally would never fail after the developing phase beside there is something really wrong with your build or with a new call you made to a MFC function. E. g. if you call a dialog by pointer where the dialog already was closed, you fastly will run into some assertion which tells you that the windows handle isn't valid or some other error. So, if you come to an assertion, you firstly make a rebuild and if that doesn't help, you look to the call stack whether there is some new statements you made which were seomehow wrong.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    Suggested Solutions

    Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
    Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
    This video discusses moving either the default database or any database to a new volume.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now