简体   繁体   中英

VC6 to VS2013 MFC Runtime Error

I am trying to upgrade a legacy product from VC6 to VS2013 using toolset 12_xp. I can get the project to compile just fine however I am getting a runtime ASSERT and it seems related to CSingleLock lock() call.

CSingleLock slock(&CV7CmnSS::m_cs); // Wait for access
    slock.Lock(m_dwTimeout); // <- this is the line that does it.

CV7CmnSS::m_cs is declared as a static object in a different class in another dll refrenced by this project.

the exe's header file has this CCriticalSection CV7CmnSS::m_cs;

as declared in CV7CmnSS header file static CCriticalSection m_cs;

I try to step through the MFC code (I know, i know...) this is about all the further I can get...

mfc120d.dll!CCriticalSection::Lock(unsigned long dwTimeout) Line 118 C++ //<-- from the call stack window

_AFXMT_INLINE BOOL (::CCriticalSection::Lock(DWORD dwTimeout))
{ 
    ASSERT(dwTimeout == INFINITE); 
    (void)dwTimeout; 

    return Lock(); 
}

the assert I box i get:

在此处输入图片说明

fairly generic..

Both the dll project are targeting the same toolset, 12_xp, both use MBCS, both are using MFC as a shared dll. Both are using Multithreaded debug dll setting.

I suspect a cross threading issue? But I am not sure how to proceed.

If there is anymore info I can provide please let me know.

EDIT:

I forgot to add this little gem, if I run the program in release without debugging I am able to get a little further with the app, however this strange message pops up....

在此处输入图片说明

The code you showed reveals the problem: there's an assert that requires the dwTimeout parameter to be INFINITE. As you can see from the code, and as mentioned in the CCriticalSection::Lock documentation, that parameter is ignored, so you can just change the code to pass INFINITE as the parameter, or just call the overload that takes no parameters (which does the same thing).

As for why the error doesn't happen in release mode, it's because asserts are only compiled in debug mode, so the assert never happens. Whatever is causing that message box is completely unrelated to the assert.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM