SysFreeString misbehaving :( ???
-
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 ofbstrTwo.m_str
, i just dont understand how the string atbstrOne.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 :-> -
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 ofbstrTwo.m_str
, i just dont understand how the string atbstrOne.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 :->Did you simplify the problem or does it really happen with code that simple? Steve
-
Did you simplify the problem or does it really happen with code that simple? Steve
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::~
-
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::~
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