Simple Unsolvable Problem - mtex.cpp(90)

Posted on 2005-04-08
Last Modified: 2013-12-03
I am working on a very large application that uses CMutex and CSingleLock for synchronisation.  I am told that this code worked perfectly under VC++ 6 but since rolling over to .NET (2003) there are problems.

The program will go down because of an ASSERT in line 90 of mtex.cpp (one of the afx files I think).  I've located this file and here is the relavent code:

CSingleLock::CSingleLock(CSyncObject* pObject, BOOL bInitialLock)
      ASSERT(pObject != NULL);
      ASSERT(pObject->IsKindOf(RUNTIME_CLASS(CSyncObject)));  //FAILS HERE

When this fires it appears that pObject passed to it appears to be a valid pointer to an object of type Win32ThreadResource which is one of our classes that inherits from CMutex (and doesn't appear to be more then a wrapper).

Anyway this code has worked for a very long time but under VS .NET it fires the above assert (then dies).  Any ideas?

Question by:skirmish76
    LVL 16

    Expert Comment

    Does your Win32ThreadResource class implements dynamicaly the CMutex MFC class?

    You need to have :

    /* Win32ThreadResource .h */
    class Win32ThreadResource : public CMutex
         int num;
         DECLARE_DYNAMIC(Win32ThreadResource )

    /* Win32ThreadResource .cpp */
    #include "stdafx.h"
    #include "Win32ThreadResource .h"

    IMPLEMENT_DYNAMIC(Win32ThreadResource , CMutex )


    Author Comment

    I added the DECLARE_DYNAMIC and IMPLEMENT_DYNAMIC macros as you suggested but the problems remains.  Thanks for suggesting them though, I read the doco for them and they really did sound like they would solve the problem (seeing as the problem was an assertion failure of KindOf() ).

    If you have any more ideas please post them.  This problem continues to be extremely frustrating.
    LVL 16

    Accepted Solution

    How is the Win32ThreadResource class declared?
    I made a class derived from CMutex and built a CSingleLock with such an object and worked fine.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
    For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    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

    20 Experts available now in Live!

    Get 1:1 Help Now