Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>// Now All Things are packed in to the Object obj.Name = bstrName; obj.Name2 = bstrname2; </code></pre> <p>I don't quite understand what do you mean by saying that things are packed since you're just copying pointers to the strings, and at the moment when you call SysFreeString obj.Name and obj.Name2 will point to an invalid block of memory. Although this code is not safe, it looks like if the source of your problem is class CFoo. You should show us more details of your code</p> <p>I suggest you to use a CComBSTR class which will take a responsibility for releasing the memory. </p> <p><strong>UPDATE</strong></p> <pre><code>#include &lt;atlbase.h&gt; using namespace ATL; ... { CComBSTR bstrname(_T("Some Name")); CComBSTR bstrname2(_T("Another Name")); // Here one may work with these variables if needed ... // Copy the local values to the Obj's member Variable bstrname.Copy(&amp;obj.Name); bstrname2.Copy(&amp;obj.Name2); } </code></pre> <p><strong>UPDATE2</strong> First of all one should free bstrCity and bstrStreetName with SysFreeString or use CComBSTR instead within this block:</p> <pre><code>if (SUCCEEDED(hr)) { BSTR bstrStreet = ::SysAllocString(table.m_pRecordData-&gt;Street); pAddress-&gt;put_StreetName(bstrStreet); BSTR bstrCity = ::SysAllocString(table.m_pRecordData-&gt;City); pAddress-&gt;put_CityName(bstrCity); // SysFreeString(bstrStreet) // SysFreeString(bstrCity) } </code></pre> <p>Consider to amplify the loop's condition !iRet with iCount &lt; lRecCount.</p> <pre><code>for(...; !iRet /* &amp;&amp; (iCount &lt; lRecCount) */; ...) </code></pre> <p>Also, here:</p> <pre><code>m_sCityName = ::SysAllocString(bstrCityName); </code></pre> <p>you allocate memory but never release it since internally CComBSTR&amp; operator = (OLESTR ..) allocates a new storage itself. One should rewrite is as follows:</p> <pre><code>m_sCityName = bstrCityName; </code></pre> <p>Everything else, looks good for me</p> <p><strong>UPDATE3</strong> Well, Heap corruption is often a consequence of writing some values outside of the allocated memory block. Say you allocate an array of length 5 and put some value to the 6th position</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload