?
Solved

CFileDialog InterlockedDecrement

Posted on 2003-03-26
5
Medium Priority
?
367 Views
Last Modified: 2013-11-20
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
Comment
Question by:MEGADETH
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 3

Expert Comment

by:aphillips
ID: 8214729
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
 

Author Comment

by:MEGADETH
ID: 8218131
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
 

Author Comment

by:MEGADETH
ID: 8225839
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
 

Accepted Solution

by:
SpideyMod earned 0 total points
ID: 8226321
PAQ'd and all 75 poitns refunded.

SpideyMod
Community Support Moderator @Experts Exchange
0
 
LVL 3

Expert Comment

by:aphillips
ID: 8229972
> Thanks aphilips for responding.

No worries.  Glad you worked out the problem.
0

Featured Post

Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

801 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