CFileDialog InterlockedDecrement

All,

I use CFileDialog to get the file path name for a user.

void CTransactionListFilterDlg::OnBtnFile()
{
//////////////////////////////////////////////////////////////////////////////////////
        // File path name
     TCHAR szFilePathName[_MAX_PATH+1];
     memset(szFilePathName, 0, _MAX_PATH+1);

     CFileDialog dlg(TRUE);
     dlg.m_ofn.lpstrFile = &szFilePathName[0];
     dlg.m_ofn.nMaxFile = _MAX_PATH;
     dlg.m_ofn.lpstrTitle = _T("Add from file");
     dlg.m_ofn.Flags =  dlg.m_ofn.Flags | OFN_ENABLESIZING |OFN_LONGNAMES | OFN_NODEREFERENCELINKS | OFN_PATHMUSTEXIST | OFN_SHAREAWARE;



     int dm = dlg.DoModal();
     if(dm != IDOK)
          return;

        CStringArray arsTransID;
     if(!ReadFile(szFilePathName, arsTransID))
          return;

//////////////////////////////////////////////////////////////////////////////////////

}


This code works until before it exits the OnBtnFile() method.

I use Boundchecker and I got a error message inside the ~CString for "InterlockedDecrement".
Something is wrong with the reference count that cause this problem.

I wonder if the problem lies because this OnBtnFile() is called after two dialog boxes and somehow there is a dangling pointer.

Any help is highly appreaciated.
I am new to this forum, so, I apologize if the points that I put does not reflect to the problem.
 

MEGADETHAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

aphillipsCommented:
I can't see anything wrong.  Can you post the code for your ReadFile function? Is there anything else in OnBtnFile after the call to ReadFile?  (If not what is the CStringArray for?)
0
MEGADETHAuthor Commented:
Below is the complete function.

If I hardcode the file path using the commented lines, it works.

It is worth mention, how this function is called. From the main application, user open an X dialog. Then on X dialog, I call Y dialog. On this Y dialog, the OnBtnFile (browse button located).



void CTransactionListFilterDlg::OnBtnFile()
{
     TCHAR szFilePathName[_MAX_PATH+1];
     memset(szFilePathName, 0, _MAX_PATH+1);

     
     CFileDialog dlg(TRUE);
     dlg.m_ofn.lpstrFile = &szFilePathName[0];
     dlg.m_ofn.nMaxFile = _MAX_PATH;
     dlg.m_ofn.lpstrTitle = _T("Add from file");
     dlg.m_ofn.Flags =  dlg.m_ofn.Flags | OFN_ENABLESIZING |OFN_LONGNAMES | OFN_NODEREFERENCELINKS | OFN_PATHMUSTEXIST | OFN_SHAREAWARE;



     int dm = dlg.DoModal();
     if(dm != IDOK)
          return;


     ASSERT(::IsWindow(m_hWnd));
 

//     CString szFilePathName = _T("");
//     szFilePathName += "C:\\Documents and Settings\\megadeth\\Desktop\\test.txt";

     CStringArray arsTransID;
     if(!ReadFile(szFilePathName, arsTransID))
          return;


     for(int i = 0; i < arsTransID.GetSize(); i++)
     {
          CString strTransID;
          strTransID = (LPCTSTR) arsTransID.GetAt(i);
          strTransID.TrimLeft();
          strTransID.TrimRight();
          if(strTransID.GetLength() > 0)
          {
               if(m_lstTrans.FindStringExact(0, (LPCTSTR) strTransID) == LB_ERR)
                    m_lstTrans.AddString((LPCTSTR) strTransID);
          }
         
          strTransID.Empty();
     }    

     
}
0
MEGADETHAuthor Commented:
I found the problem. Something is not right with the window handle. I use Win API "GetOpenFileName", and specify the handle. It works.

Thanks aphilips for responding.
0
SpideyModCommented:
PAQ'd and all 75 poitns refunded.

SpideyMod
Community Support Moderator @Experts Exchange
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
aphillipsCommented:
> Thanks aphilips for responding.

No worries.  Glad you worked out the problem.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.