CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 44
  1. #16
    Join Date
    Jan 2009
    Posts
    399

    Re: Emptying CString

    Quote Originally Posted by GCDEF View Post
    Where is m_sError declared?
    In the header of CMyObject (derived from CObject).

  2. #17
    Join Date
    Jan 2009
    Posts
    399

    Re: Emptying CString

    Quote Originally Posted by VictorN View Post
    Set a break point at the line
    Code:
    m_sError.Empty();
    , 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(""));

  3. #18
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: Emptying CString

    Quote Originally Posted by mesajflaviu View Post
    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

  4. #19
    Join Date
    Jan 2009
    Posts
    399

    Re: Emptying CString

    I will return in this afternoon with debugging results ... my app is not on my office ... See you soon.

  5. #20
    Join Date
    Jan 2009
    Posts
    399

    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 ...

  6. #21
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    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.

  7. #22
    Join Date
    Jan 2009
    Posts
    399

    Re: Emptying CString

    Thank you ... I will looking for what you said.

  8. #23
    Join Date
    Jan 2009
    Posts
    399

    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 ?

  9. #24
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: Emptying CString

    Try to use the debugger to see how this CString instance was initialized.
    Victor Nijegorodov

  10. #25
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Emptying CString

    Quote Originally Posted by mesajflaviu View Post
    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.

  11. #26
    Join Date
    Jan 2009
    Posts
    399

    Re: Emptying CString

    Quote Originally Posted by Arjay View Post
    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 ...

  12. #27
    Join Date
    Jan 2009
    Posts
    399

    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 !

  13. #28
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: Emptying CString

    Quote Originally Posted by mesajflaviu View Post
    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

  14. #29
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,825

    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)

  15. #30
    Join Date
    Jan 2009
    Posts
    399

    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.

Page 2 of 3 FirstFirst 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured