0

E_OUTOFMEMORY、ヒープの破損

HRESULT AllocateAndFillOutParameters(DWORD * a_Attrib_Count, BSTR ** a_AttribName, DWORD** a_AttribId,BSTR** a_AttribDescription, BSTR** a_AttribDataType, 
    BSTR** a_AttribAdvanceDataType,DWORD** a_attribfieldlength, VECTOROFATTRIBUTESSTRUCT a_vectAttributes) 
{ 
HRESULT hr = S_OK; 
VECTOROFATTRIBUTESSTRUCT::iterator itr_vectCategory = a_vectAttributes.begin(); 

    // Memory Allocation 
    *a_Attrib_Count = a_vectAttributes.size(); 
    *a_AttribName = (BSTR*)CoTaskMemAlloc(*a_Attrib_Count * sizeof(BSTR)); 
    *a_AttribDescription = (BSTR*)CoTaskMemAlloc(*a_Attrib_Count * sizeof(BSTR)); 
    *a_AttribId = (DWORD*)CoTaskMemAlloc(*a_Attrib_Count * sizeof(DWORD)); 
    *a_AttribDataType = (BSTR*)CoTaskMemAlloc(*a_Attrib_Count * sizeof(BSTR)); 
    *a_AttribAdvanceDataType = (BSTR*)CoTaskMemAlloc(*a_Attrib_Count * sizeof(BSTR)); 
    *a_attribfieldlength = (DWORD*)CoTaskMemAlloc(*a_Attrib_Count * sizeof(DWORD)); 
    // 

    for(int i=0 ;itr_vectCategory != a_vectAttributes.end(); itr_vectCategory++, i++) 
    { 
     *((*a_AttribName)+i) = SysAllocString(itr_vectCategory->m_strAttributeName.c_str()); 
     *((*a_AttribId)+i) = itr_vectCategory->m_dwAttributeId; 
     *((*a_AttribDescription)+i) = SysAllocString(itr_vectCategory->m_strAttributeDescription.c_str()); 
     *((*a_AttribDataType)+i) = SysAllocString(itr_vectCategory->m_strAttributeDataType.c_str()); 
     *((*a_AttribAdvanceDataType)+i) = SysAllocString(itr_vectCategory->m_strAttributeAdvanceDataType.c_str()); 
     *((*a_attribfieldlength)+i) = (itr_vectCategory->m_dwAttributeFieldLength); 

    } 

return hr; 
} 

それは、ヒープ破損の実行時例外を与えるが、私は間違った方法で割り当てることですか? ありがとうございます。

+0

この生産コードはありますか? –

+1

ループでは、実際に '(* a_AttribName)+ 1'にする必要がありますか? '1'の代わりに' i'を付けてはいけませんか? –

+0

はい、ここに間違いを入力しています。 – Ehsank

答えて

0

あなたの誤差がある場合、私はあなたを伝えることはできませんが、私はあなたがヒープ破損が実際に発生したエラーをキャッチすることを可能にするgflagsプログラムを使用して、ページヒープのデバッグを有効にするDebugging Tools for Windows、その後reading the docsのダウンロードをお勧めします。