CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Threaded View

  1. #1
    Join Date
    Jan 2009
    Posts
    399

    Using CString into static method

    I am stuck into a strange problem. I have MDI app, which has a struct into CDocument:
    Code:
    class CMyDoc : public CDocument
    {
    ...
    
    struct SRecord
    {
        SRecord(){}
        virtual ~SRecord(){}
        CString sName;
        CString sState;
        CString sDateu;
        CString sDatec;
    };
    
    CTypedPtrArray<CPtrArray, SRecord*> m_arrRecord;
    and somewhere in document I load this struct with data:
    Code:
        SRecord* pItem = new SRecord;
        pItem->sName        = saItem.GetAt(ML_ASSETNAME);
        pItem->sState       = saItem.GetAt(ML_STATE);
        pItem->sDateu       = saItem.GetAt(ML_DATEU;
        pItem->sDatec       = saItem.GetAt(ML_DATEC);
        m_arrRecord.Add(pItem);
    ok by now. I am trying to sort data:
    Code:
    void CMyDoc::SortData(int nColumn, BOOL bAscending)
    {
    switch(nColumn)
    {
    case 9:
        if(bAscending)qsort((void*)m_arrRecord.GetData(), m_arrRecord.GetSize(), sizeof(SRecord), CompareDateUAscending);
        else qsort((void*)m_arrRecord.GetData(), m_arrRecord.GetSize(), sizeof(SRecord), CompareDateUDescending);
        break;
    ...
    }
    but the problem occur when data is access in static method:
    Code:
    //static method:
    int CMyDoc::CompareDateUDescending(const void* arg1, const void* arg2)
    {
    SRecord* Record1 = *(SRecord**)arg1;    // <-- OK
    SRecord* Record2 = *(SRecord**)arg2;    // <-- Unhandled exception* see note below
    
    if(Record1->sDateu.IsEmpty() || Record2->sDateu.IsEmpty())
        return 0;
    
    COleDateTime dL, dR;
    dL.ParseDateTime(Record1->sDateu);
    dR.ParseDateTime(Record2->sDateu);
    
    return (dL == dR ? 0 : (dL < dR ? 1 : -1));
    }
    *and the crash told me:
    "An unhandled exception was encountered during a user callback."

    What could be the problem ? Can you help me ? Thank you.
    Last edited by mesajflaviu; February 13th, 2017 at 06:58 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured