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. how to deal with SafeArrayDestroy error?

how to deal with SafeArrayDestroy error?

Scheduled Pinned Locked Moved C / C++ / MFC
debuggingquestiondata-structureshelptutorial
3 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.
  • L Offline
    L Offline
    liuyue
    wrote on last edited by
    #1

    IHTMLDocument2 *document; // Declared earlier in my code HRESULT hr = GetHtmlDocument()->QueryInterface(IID_IHTMLDocument2,(void**) &document); if (!SUCCEEDED(hr)) { return; } HRESULT hresult = S_OK; VARIANT *param; SAFEARRAY *sfArray; BSTR bstr = SysAllocString(OLESTR("hjgjhgjghjhgjhgjhg

    ")); sfArray = SafeArrayCreateVector(VT_VARIANT, 0, 2); // Creates a new one-dimensional array if (sfArray == NULL || document == NULL) { goto cleanup; } hresult = SafeArrayAccessData(sfArray,(LPVOID*) & param);//获取数组元素 param[0].vt = VT_BSTR; param[0].bstrVal = bstr; param[1].vt = VT_R8; param[1].dblVal = 3.4567; hresult = SafeArrayUnaccessData(sfArray); hresult = document->writeln(sfArray); cleanup: SysFreeString(bstr); if (sfArray != NULL) { SafeArrayDestroy(sfArray); } when i debug , in SafeArrayDestroy(sfArray),an error arises : HEAP[Book.exe]: Invalid Address specified to RtlSizeHeap( 00140000, 02CF0358 ),and there is a messagebox: user breakpoint called from code at ox7c921230. how can i dispose of it? thanks.

    J 1 Reply Last reply
    0
    • L liuyue

      IHTMLDocument2 *document; // Declared earlier in my code HRESULT hr = GetHtmlDocument()->QueryInterface(IID_IHTMLDocument2,(void**) &document); if (!SUCCEEDED(hr)) { return; } HRESULT hresult = S_OK; VARIANT *param; SAFEARRAY *sfArray; BSTR bstr = SysAllocString(OLESTR("hjgjhgjghjhgjhgjhg

      ")); sfArray = SafeArrayCreateVector(VT_VARIANT, 0, 2); // Creates a new one-dimensional array if (sfArray == NULL || document == NULL) { goto cleanup; } hresult = SafeArrayAccessData(sfArray,(LPVOID*) & param);//获取数组元素 param[0].vt = VT_BSTR; param[0].bstrVal = bstr; param[1].vt = VT_R8; param[1].dblVal = 3.4567; hresult = SafeArrayUnaccessData(sfArray); hresult = document->writeln(sfArray); cleanup: SysFreeString(bstr); if (sfArray != NULL) { SafeArrayDestroy(sfArray); } when i debug , in SafeArrayDestroy(sfArray),an error arises : HEAP[Book.exe]: Invalid Address specified to RtlSizeHeap( 00140000, 02CF0358 ),and there is a messagebox: user breakpoint called from code at ox7c921230. how can i dispose of it? thanks.

      J Offline
      J Offline
      Jose Lamas Rios
      wrote on last edited by
      #2

      liuyue wrote: SysFreeString(bstr); if (sfArray != NULL) { SafeArrayDestroy(sfArray); From the SafeArrayDestroy documentation:

      "Remarks Safe arrays of variant will have VariantClear called on each member [...]."

      I think SafeArrayDestroy is calling VariantClear on the first element of the array, which in turn will call SysFreeString on the BSTR you already released. Try not calling SysFreeString before SafeArrayDestroy and see if the error persists. -- jlr http://jlamas.blogspot.com/[^]

      L 1 Reply Last reply
      0
      • J Jose Lamas Rios

        liuyue wrote: SysFreeString(bstr); if (sfArray != NULL) { SafeArrayDestroy(sfArray); From the SafeArrayDestroy documentation:

        "Remarks Safe arrays of variant will have VariantClear called on each member [...]."

        I think SafeArrayDestroy is calling VariantClear on the first element of the array, which in turn will call SysFreeString on the BSTR you already released. Try not calling SysFreeString before SafeArrayDestroy and see if the error persists. -- jlr http://jlamas.blogspot.com/[^]

        L Offline
        L Offline
        liuyue
        wrote on last edited by
        #3

        i call SysFreeString(bstr) for bstr , the param[0] is equal to bstr , and has nothing to bstr . i release bstr , but param[0] still exist. what's more, when i make param[1].vt = VT_BSTR; param[1].bstrVal = bstr;, the problem disappears. so i think the problem has nothing with SysFreeString(bstr).

        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