Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 386
  • Last Modified:

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.
 

0
MEGADETH
Asked:
MEGADETH
  • 2
  • 2
1 Solution
 
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
 
aphillipsCommented:
> Thanks aphilips for responding.

No worries.  Glad you worked out the problem.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now