ASSERT(AfxGetThread() == NULL) in CWinApp


  • // MFC_DLL.h : main header file for the MFC_DLL DLL // #pragma once #ifndef __AFXWIN_H__ #error "include 'stdafx.h' before including this file for PCH" #endif #include "resource.h" // main symbols #ifdef MFC_DLL_IMPORT #define EXPORTED __declspec(dllimport) #else #define EXPORTED __declspec(dllexport) #endif // CMFC_DLLApp // See MFC_DLL.cpp for the implementation of this class // class EXPORTED CMFC_DLLApp : public CWinApp { public: CMFC_DLLApp(); void HelloWorld(void); // Overrides public: virtual BOOL InitInstance(); DECLARE_MESSAGE_MAP() }; CWinApp::CWinApp(LPCTSTR lpszAppName) { if (lpszAppName != NULL) m_pszAppName = _tcsdup(lpszAppName); else m_pszAppName = NULL; // initialize CWinThread state AFX_MODULE_STATE* pModuleState = _AFX_CMDTARGET_GETSTATE(); ENSURE(pModuleState); AFX_MODULE_THREAD_STATE* pThreadState = pModuleState->m_thread; ENSURE(pThreadState); ASSERT(AfxGetThread() == NULL); <<<<-----Assert here

    I created a <label for="DLL_TYPE_REGULAR" id="DLL_TYPE_REGULAR_LABEL">Regular DLL using shared MFC DLL</label>  called CMFC_DLLApp.  I then built an MFC form that has a button to instantiate the class and use it.  When I instantiate the class, it asserted in CWinApp constructor.  A couple questions:

    1. What am I doing wrong that caused the Assert?

    2. Why is the DLL being inherited from CWinApp?  I just want an MFC class DLL that contains a bunch of simple routines that has nothing to do with GUI.  As simple as Max(), Min()..that kind of stuff.  Is there anyway to do that?

    3. In order to use MFC DLL, does that mean I need to build a GUI interface around it?

    I am using Visual Studio 2012
    • Edited by Max21226 Wednesday, September 04, 2013 9:02 PM
    Wednesday, September 04, 2013 8:58 PM