Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. SysFreeString misbehaving :( ???

SysFreeString misbehaving :( ???

Scheduled Pinned Locked Moved C / C++ / MFC
comhelptutorialquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nutkase
    wrote on last edited by
    #1

    Ok the problem is a lil strange, i am all confused how the hell is this possible, lemme explain with an example... void Test() { CComBSTR bstrOne("abc"); { CComBSTR bstrTwo("xyz"); } AfxMessageBox(CString(bstrOne)); } Now this is what happens sometimes.. when the destructor of bstrTwo is called it calls ::SysFreeString( m_str ) and this free's the string of bstrOne. I have checked the address passed to ::SysFreeString it is the address of bstrTwo.m_str, i just dont understand how the string at bstrOne.m_str is freed. If anyone can explain me this. One more thing it doesn't always happens this way.. It just happens when i copy data on clipboard. The only special thing i am doing is that i have written a custom COM component to handle my Clipboard requests. This actually happens in that code. I understand there is some problem with my code.. but what i dont understand is how does ::SysFreeString(something) frees something else. :-> WHATEVER :->

    S 1 Reply Last reply
    0
    • N nutkase

      Ok the problem is a lil strange, i am all confused how the hell is this possible, lemme explain with an example... void Test() { CComBSTR bstrOne("abc"); { CComBSTR bstrTwo("xyz"); } AfxMessageBox(CString(bstrOne)); } Now this is what happens sometimes.. when the destructor of bstrTwo is called it calls ::SysFreeString( m_str ) and this free's the string of bstrOne. I have checked the address passed to ::SysFreeString it is the address of bstrTwo.m_str, i just dont understand how the string at bstrOne.m_str is freed. If anyone can explain me this. One more thing it doesn't always happens this way.. It just happens when i copy data on clipboard. The only special thing i am doing is that i have written a custom COM component to handle my Clipboard requests. This actually happens in that code. I understand there is some problem with my code.. but what i dont understand is how does ::SysFreeString(something) frees something else. :-> WHATEVER :->

      S Offline
      S Offline
      Stephen Hewitt
      wrote on last edited by
      #2

      Did you simplify the problem or does it really happen with code that simple? Steve

      N 1 Reply Last reply
      0
      • S Stephen Hewitt

        Did you simplify the problem or does it really happen with code that simple? Steve

        N Offline
        N Offline
        nutkase
        wrote on last edited by
        #3

        Well actually i simplified it alot.. there are many lines of code there of course. What i am really curious about was that i pass some address X to the SysFreeString and it just frees the string at address Y. I have check the addresses in Memory View and they are different. I am just all confused. The behaviour is consistent in one way, if i have 2 string it will always free the string1 when asked to destroy string2.:confused::~

        S 1 Reply Last reply
        0
        • N nutkase

          Well actually i simplified it alot.. there are many lines of code there of course. What i am really curious about was that i pass some address X to the SysFreeString and it just frees the string at address Y. I have check the addresses in Memory View and they are different. I am just all confused. The behaviour is consistent in one way, if i have 2 string it will always free the string1 when asked to destroy string2.:confused::~

          S Offline
          S Offline
          Stephen Hewitt
          wrote on last edited by
          #4

          I suspect the problem is in some of the code you edited out. I have used SysFreeString many times and never had any problems like yours. Perhaps if you can produce some code that will actually reproduce the problem you will get a solution. Steve

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups