-
February 2nd, 2015, 08:42 AM
#16
Re: Emptying CString
Originally Posted by GCDEF
Where is m_sError declared?
In the header of CMyObject (derived from CObject).
-
February 3rd, 2015, 02:40 AM
#17
Re: Emptying CString
Originally Posted by VictorN
Set a break point at the line , start debugger, and when it breaks it this line press F11 to step into MS CString::Empty code to see whet happens and why.
After I used excel wrapper, I have in CString::m_pchData the buggy string: "Excel.Application.12" ... no matter what ... The workaround was to format
Code:
m_sError.Format(_T(""));
-
February 3rd, 2015, 03:46 AM
#18
Re: Emptying CString
Originally Posted by mesajflaviu
After I used excel wrapper, I have in CString::m_pchData the buggy string: "Excel.Application.12" ... no matter what ... The workaround was to format
Code:
m_sError.Format(_T(""));
It is not a workaround.
Did you try to debug the CString::Empty code?
Victor Nijegorodov
-
February 3rd, 2015, 04:05 AM
#19
Re: Emptying CString
I will return in this afternoon with debugging results ... my app is not on my office ... See you soon.
-
February 3rd, 2015, 11:19 AM
#20
Re: Emptying CString
Here is the debugging result:
Code:
void CString::Empty()
{
if (GetData()->nDataLength == 0) // m_pchData => "Some random error"
return;
if (GetData()->nRefs >= 0) // m_pchData => "The same random error"
Release(); // m_pchData => "Excel.Application.12"
else
*this = &afxChNil;
ASSERT(GetData()->nDataLength == 0); // m_pchData => "Excel.Application.12"
ASSERT(GetData()->nRefs < 0 || GetData()->nAllocLength == 0); // m_pchData => "Excel.Application.12"
}
void CString::Release()
{
if (GetData() != _afxDataNil) // m_pchData => "The same random error"
{
ASSERT(GetData()->nRefs != 0);
if (InterlockedDecrement(&GetData()->nRefs) <= 0) // m_pchData => "The same random error"
FreeData(GetData()); // m_pchData => "Excel.Application.12"
Init(); // m_pchData => "Excel.Application.12"
}
}
weird ... I have to dig in ...
-
February 3rd, 2015, 11:23 AM
#21
Re: Emptying CString
At this point I'd be looking for memory corruption somewhere else in your program. CString::Empty works. You've probably stepped on something that's making your program act strangely but without causing a crash. Look for array overruns, etc.
-
February 3rd, 2015, 11:47 AM
#22
Re: Emptying CString
Thank you ... I will looking for what you said.
-
February 4th, 2015, 06:06 AM
#23
Re: Emptying CString
I am thinking that the problem is inside of excel wrapper, that's why I get these garbage's in m_sError ... I am right ?
-
February 4th, 2015, 06:09 AM
#24
Re: Emptying CString
Try to use the debugger to see how this CString instance was initialized.
Victor Nijegorodov
-
February 4th, 2015, 09:48 AM
#25
Re: Emptying CString
Originally Posted by mesajflaviu
I am thinking that the problem is inside of excel wrapper, that's why I get these garbage's in m_sError ... I am right ?
I think the problem is you need to capture the error conditions (catch exceptions, check HRESULTS, etc) that cause the string to get populated, not check the string at some point later and wonder why it has something in it.
-
February 4th, 2015, 12:26 PM
#26
Re: Emptying CString
Originally Posted by Arjay
I think the problem is you need to capture the error conditions (catch exceptions, check HRESULTS, etc) that cause the string to get populated, not check the string at some point later and wonder why it has something in it.
I think you are perfectly right ... the problem is in somewhere else ...
-
February 26th, 2015, 04:20 AM
#27
Re: Emptying CString
I found the origin of the problem: before I work to excel wrapper, I opened registry and I didn't close them ... in case that everyone will face with the same problem ... thank you all !
-
February 26th, 2015, 04:24 AM
#28
Re: Emptying CString
Originally Posted by mesajflaviu
I found the origin of the problem: before I work to excel wrapper, I opened registry and I didn't close them ... in case that everyone will face with the same problem ... thank you all !
What does the "opening" registry have to do with the CString behaviour?
Victor Nijegorodov
-
February 26th, 2015, 04:38 AM
#29
Re: Emptying CString
If the underlying problem is memory corruption, then adding/changing some lines of code that doesn't directly address the problem (and which can be justified to have fixed the problem) is unlikely to fix the problem. The underlying problem could still be present but affecting some other part of the program in which it isn't so obvious - so the original symptoms 'disappear' so it looks like the problem has been fixed when it hasn't.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
March 13th, 2015, 04:50 AM
#30
Re: Emptying CString
After all, I really found the problem: instead of
Code:
// Get the Version information
lRet = RegQueryValueEx(hKeyC, NULL, NULL, NULL, (BYTE*)(LPCTSTR)sVersion, &cSize);
I wrote:
Code:
// Get the Version information
lRet = RegQueryValueEx(hKeyC, NULL, NULL, NULL, (BYTE*)sVersion.GetBuffer(_MAX_PATH), &cSize);
sVersion.ReleaseBuffer();
Thank you all for your attention.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|