none
C++ Unhandled exception at 0x506030ca (mfc100d.dll)

    Question

  • At the end of a routine and returning to the calling routine my program is getting an exception.

    Specifically in atlsimpstr.h on the execution of the ATLASSERT line.  At that point nRefs is equal to -1 and the exception is thrown at that point.  However, I am not sure why/how nRefs was set to -1 - as I walk through the code using the debugger it is unclear where nRefs was set to that value.

    voidRelease() throw()

    {

    ATLASSERT( nRefs != 0 );

    if( _AtlInterlockedDecrement( &nRefs ) <= 0 )

    {

    pStringMgr->Free(

    this);

    }

    }


    Saturday, July 12, 2014 5:38 PM

Answers

  • Ok - I now have it working!

    In the routine (previously provided) I declared etx as a CString vice as a char and initialized its value.

    Then I removed casting it as a CString in the lstrcat as well.  Then I removed the use of sscanf and this removed the problem.  I suspect casting etx as a CString is what was causing the issue in general.

    BTW - thanks for the general debugging approach as I am still working on this application and it is coming in handy to solve other issues with this as well.

    Monday, July 14, 2014 7:23 PM

All replies

  • Hi,

    Thanks for posting here.

    Firstly as far as I know that nRefs represents the current reference count of the CStringData object. This value is used in determining how many string objects are sharing the same CStringData object. The assertion statement in discussion is thrown from the Release method of CStringData.

    My suggestion is to first find out the variable that holds the CStringData struct, then search for all places of using the variable in your code to see whether there’s any misuse.  To find out the variable that holds the CStringData, you can click “Retry” when you see the assert dialog which will start up your JIT debugger (e.g. Visual Studio or windbg) to attach to the process. After the debugger is attached, open the call-stack window. (In Visual Studio, the call-stack window can be opened in Debug menu -> Windows -> Call Stack).

    The first part of the call-stack should belong to MFC/ATL CString(Data). Your own codes follow that part. Find the topmost line of your codes in the call-stack, and double click the line. You will be navigated to source code that corresponds to the stack frame, and the code line that throws the error is highlighted in the debugger. The line should also tell you the variable holding the CStringData struct.

    Then you can do a search in your project for the variable, and list all its uses. Pay special attention to any possibility that the variable was double-freed or was corrupted somewhere.

    In addition, how and where did you declare the string variables? I find someone has ever met this kind of issue and he resolved the issue by declaring the strings as global variables. You may also try like this.

    http://www.codeproject.com/Questions/769056/Converting-Cplusplus-application-from-bit-to-bit

    Please try the above suggestion. If you have any questions, please feel free to let me know.

    May


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.




    Monday, July 14, 2014 7:43 AM
    Moderator
  • Ok - First - Thanks for your help! I used the approach you suggested and arrived at the same place I was before, but examining Call Stack helped verify what was happening.  The last line in my code to be invoked is the "}" at the end of the routine below.  I don't know what variable mfc100d.dll is trying to release.  Any further recommendations?

    void

    CMainFrame::CreateResponseBuffer1()

    {

    CString exp_time;

    CString can_time;

    CString str_length;

    CString special_msg;

    charetx;

    exp_time = (CString)(set1.m_expiration_date.Format(

    "%b %d %Y"));

    can_time = (CString)(set1.m_cancellation_date.Format(

    "%b %d %Y"));

    str_length .Format(

    "%d", set1.m_length);

    lstrcat(sRspBuff,

    "REG/");

    lstrcat(sRspBuff, set1.m_boat_number);

    lstrcat(sRspBuff, set1.m_boat_number_suffix);

    lstrcat(sRspBuff,

    " ");

    if(set1.m_boat_status == "1")

    {

    lstrcat(sRspBuff,

    "REY/");

    lstrcat(sRspBuff, exp_time);

    lstrcat(sRspBuff,

    " ");

    }

    if(set1.m_boat_status == "5"&& set1.m_boat_code != "7")

    {

    special_msg =

    "CANCELED";

    lstrcat(sRspBuff,

    "REY/");

    lstrcat(sRspBuff, can_time);

    lstrcat(sRspBuff,

    " ");

    }

    if(set1.m_boat_status == "5"&& set1.m_boat_code == "7")

    {

    special_msg =

    "CANCELED - BAD CHECK RECIEVED";

    lstrcat(sRspBuff,

    "REY/");

    lstrcat(sRspBuff, can_time);

    lstrcat(sRspBuff,

    " ");

    }

    if(set1.m_boat_status == "8")

    {

    special_msg =

    "REPORTED STOLEN TO GIFC";

    lstrcat(sRspBuff,

    "REY/");

    lstrcat(sRspBuff, can_time);

    lstrcat(sRspBuff,

    " ");

    }

    if(set1.m_boat_status == "9")

    {

    special_msg =

    "EXPIRED";

    lstrcat(sRspBuff,

    "REY/");

    lstrcat(sRspBuff, exp_time);

    lstrcat(sRspBuff,

    " ");

    }

        lstrcat (sRspBuff,

    "\r");

    lstrcat (sRspBuff,

    "\r");

    lstrcat(sRspBuff,

    "SOC/");

    lstrcat(sRspBuff, set1.m_ssn);

    lstrcat(sRspBuff,

    "\r");

    lstrcat(sRspBuff, set1.m_fname);

    lstrcat(sRspBuff,

    " ");

    lstrcat(sRspBuff, set1.m_middle_init);

    lstrcat(sRspBuff,

    " ");

    lstrcat(sRspBuff, set1.m_lname);

    lstrcat(sRspBuff,

    " ");

    lstrcat(sRspBuff, set1.m_suffix);

    lstrcat(sRspBuff,

    " ");

    lstrcat(sRspBuff,

    "\r");

    lstrcat(sRspBuff, set1.m_address1);

    lstrcat(sRspBuff,

    "\r");

    lstrcat(sRspBuff, set1.m_address2);

    lstrcat(sRspBuff,

    "\r");

    lstrcat(sRspBuff, set1.m_city);

    lstrcat(sRspBuff,

    " ");

    lstrcat(sRspBuff, set1.m_state);

    lstrcat(sRspBuff,

    " ");

    lstrcat(sRspBuff, set1.m_zip);

    lstrcat(sRspBuff,

    "\r");

    lstrcat(sRspBuff,

    "\r");

    lstrcat(sRspBuff,

    "BMA/");

    lstrcat(sRspBuff, set1.m_make_boat);

    lstrcat(sRspBuff,

    " ");

    lstrcat(sRspBuff,

    "BYR/");

    lstrcat(sRspBuff, set1.m_model_year);

    lstrcat(sRspBuff,

    " ");

    lstrcat(sRspBuff,

    "BLE/");

    lstrcat(sRspBuff, str_length);

    lstrcat(sRspBuff,

    " ");

    lstrcat(sRspBuff,

    "BHN/");

    lstrcat(sRspBuff, set1.m_hull_id);

    lstrcat(sRspBuff,

    " ");

    lstrcat(sRspBuff,

    "\r");

    lstrcat(sRspBuff,

    "BMO/");

    lstrcat(sRspBuff, set1.m_model_boat_code);

    lstrcat(sRspBuff,

    " ");

    lstrcat(sRspBuff,

    "HUL/");

    lstrcat(sRspBuff, set1.m_hull_material_code);

    lstrcat(sRspBuff,

    " ");

    lstrcat(sRspBuff,

    "PRO/");

    lstrcat(sRspBuff, set1.m_prop_code );

    lstrcat(sRspBuff,

    " ");

    lstrcat(sRspBuff,

    "\r");

    lstrcat(sRspBuff,

    "\r");

    if(set1.m_boat_status == "2")

    {

    special_msg =

    "TITLE ONLY";

    }

    if(recNumber == 0)

    {

    special_msg =

    "NO RECORD FOUND";

    }

    lstrcat(sRspBuff, special_msg);

    sscanf(ETX,

    "%X", &etx);

        lstrcat(sRspBuff, (CString)etx);

    //AfxMessageBox(sRspBuff);


    InitializeBoatSet();

    } // This is the last line in my code that executes before the error occurs.

    Monday, July 14, 2014 1:09 PM
  • Ok - something odd is occuring when the sscanf(ETX, "%X", &etx); executes - it appears to "walk on top of" the special_msg variable - however I am not certain why. ETX is  defined by #define ETX "0x03"

    Not sure why this would occur.

    Monday, July 14, 2014 3:18 PM
  • Ok - I now have it working!

    In the routine (previously provided) I declared etx as a CString vice as a char and initialized its value.

    Then I removed casting it as a CString in the lstrcat as well.  Then I removed the use of sscanf and this removed the problem.  I suspect casting etx as a CString is what was causing the issue in general.

    BTW - thanks for the general debugging approach as I am still working on this application and it is coming in handy to solve other issues with this as well.

    Monday, July 14, 2014 7:23 PM