MEGADETH
asked on
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(szFilePathNam e, 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.
I use CFileDialog to get the file path name for a user.
void CTransactionListFilterDlg:
{
//////////////////////////
// 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(szFilePathNam
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.
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?)
ASKER
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\\Deskto p\\test.tx t";
CStringArray arsTransID;
if(!ReadFile(szFilePathNam e, 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.FindStringEx act(0, (LPCTSTR) strTransID) == LB_ERR)
m_lstTrans.AddString((LPCT STR) strTransID);
}
strTransID.Empty();
}
}
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:
{
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\\Deskto
CStringArray arsTransID;
if(!ReadFile(szFilePathNam
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.FindStringEx
m_lstTrans.AddString((LPCT
}
strTransID.Empty();
}
}
ASKER
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.
Thanks aphilips for responding.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
> Thanks aphilips for responding.
No worries. Glad you worked out the problem.
No worries. Glad you worked out the problem.