The global CWinApp object initialized twice when vs2008 upgrade to vs2017
In vs2008, My Project works normally, but when I upgrade to vs201, the global CWinApp object be called twice and occur the error: "ASSERT(AfxGetThread() == NULL); (appcore.cpp)"
I dont know what happen! = _ =!!!
C++
Visual Studio Debugging
-
YujianYao-MSFT 4,281 Reputation points • Microsoft Vendor
2022-02-15T07:54:38.063+00:00 Hi @ShowMeYourCode ,
I downloaded VS2017 and tested
CWinApp
with the following code, the problem you mentioned did not appear. Could please provide a minimal reproducible example?#include<afxwin.h> class CmyFrameWnd :public CFrameWnd { }; class CMyWinApp :public CWinApp { public: CMyWinApp() { } virtual BOOL InitInstance() { CmyFrameWnd* pFrame = new CmyFrameWnd; pFrame->Create(NULL, L"sda"); m_pMainWnd = pFrame; pFrame->ShowWindow(SW_SHOW); pFrame->UpdateWindow(); return TRUE; } }; CMyWinApp theApp;
-
ShowMeYourCode 1 Reputation point
2022-02-15T08:07:14.793+00:00 Thank you for your apply!
I did the same test and works normally.//********in the header file class CMyApp: public CWinApp { public: CMyApp(); ~CMyApp() { } virtual BOOL InitInstance(); virtual BOOL OnIdle(LONG ICount); virtual int ExitInstance(); virtual int Run(); virtual BOOL PumpMessage(); virtual BOOL PreTranslateMessage(MSG* pMsg); }; //********in the source file CMyApp theApp; //it will be called twice CMyApp::CMyApp() { } CMyApp::InitInstance() { //register the exception handler function curl_global_init(CURL_GLOBAL_ALL); //init the curl, rely on curl library // and so on }
In my opinion, This error may be related to the upgrade vs version.
-
YujianYao-MSFT 4,281 Reputation points • Microsoft Vendor
2022-02-15T09:15:49.42+00:00 Hi @ShowMeYourCode ,
It looks like the problem is not from the code, I suggest you go to DC to report this issue.
-
RLWA32 45,236 Reputation points
2022-02-15T09:26:13.24+00:00 Set a breakpoint on the CMyApp constructor. When it is called the second time you should be able to examine the call stack. Hopefully that will assist you in locating the problem. If it is not called twice then set the breakpoint on the MFC CWinApp constructor and try again. And the MFC assertion should give you the option of debugging the code. If you do, you should also be able to examine the call stack at that point.
-
ShowMeYourCode 1 Reputation point
2022-02-15T09:51:37.987+00:00 I have set the breakpoint on the "CMyApp theApp". In vs2017, I cant into the source of CWinApp ctor function.
This the call stack:
-
ShowMeYourCode 1 Reputation point
2022-02-15T09:52:04.747+00:00 OK, Thank you very much.
-
RLWA32 45,236 Reputation points
2022-02-15T12:00:52.14+00:00 You need to load symbol files to see a complete call stack.
Go to Debug->Options->Symbols and enable the Microsoft Symbol Server and set a path for the downloaded symbol files. For example,
Then, when your breakpoint is hit you should be able to step into the MFC source code for the CWinApp constructor (give the VS Debugger time to load the various symbol files) and the call stack should look something like this -
-
ShowMeYourCode 1 Reputation point
2022-02-16T01:20:51.137+00:00 Thanks to the patient reply.
My project is in the private network env, cant load symbols.
And I have do the test: Create new project with vs2017 and debug, it can into the mfc source code, but I can't enter it through debugging of my project.
I found that my project rely on mfc140d.dll, I don't know if it has anything to do with this. -
RLWA32 45,236 Reputation points
2022-02-16T10:09:43.81+00:00 You can refer to MFC shared DLL naming conventions for an explanation of how MFC DLLs are named.
-
RLWA32 45,236 Reputation points
2022-02-16T10:35:45.333+00:00 If you use the VS2008 MFC new application wizard to create a new project and then build that project using VS2017 does the application execute correctly? If it does, that would indicate that the problem is in your code, not with VS2017 or MFC.
-
ShowMeYourCode 1 Reputation point
2022-02-17T02:32:47.423+00:00 Yes, I also do the same test, and it works normally.
It's really let me feel confused.
I think if the code is wrong, Why does it work in vs2008 version? -
RLWA32 45,236 Reputation points
2022-02-17T08:58:44.453+00:00 Sorry, but without more information its not possible for me to diagnose the problem.
-
ShowMeYourCode 1 Reputation point
2022-02-17T09:05:59.333+00:00 Thank you very much.
It's my mistake =_=
Sign in to comment