none
SAFEARRAY throws An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll

    General discussion

  • Hi,

    Below is my VC++ code to log messages into flat file. When whenever i tried to login unicode characters. i am getting error "An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll".

    HRESULT hr;
    DWORD cbNofData;
    cbNofData = pParser->GetDataLength();

    SAFEARRAY *pSA;
    SAFEARRAYBOUND aDim[1];
    aDim[0].lLbound= 0; 
    aDim[0].cElements= cbNofData * 2;
    pSA= SafeArrayCreate( VT_VARIANT, 1, aDim );  

    LPWSTR pActualData = NULL;
    SafeArrayAccessData(pSA,(void **)&pActualData);

    hr = pParser->FillData( m_ValueMap, pActualData, cbNofData, lcidNofData, true );

    SafeArrayUnaccessData( pSA );
    *pNofData = pSA;

    Please help me out to resolve this error. Thanks in Advance.

    Wednesday, July 18, 2012 6:53 AM

All replies

  • RAJESH_BALA wrote:

    SAFEARRAY *pSA;
    SAFEARRAYBOUND aDim[1];
    aDim[0].lLbound= 0;
    aDim[0].cElements= cbNofData * 2;
    pSA= SafeArrayCreate( VT_VARIANT, 1, aDim );

    LPWSTR pActualData = NULL;
    SafeArrayAccessData(pSA,(void **)&pActualData);

    You've created a safearray of VARIANT's, but you are treating it as if  it were an array of bytes. Figure out what you want: either create a  safearray of bytes (pass VT_UI1 to SafeArrayCreate), or pack each byte  individually into a variant.


    Igor Tandetnik

    Wednesday, July 18, 2012 1:40 PM
  • On 7/18/2012 2:53 AM, RAJESH_BALA wrote:

    SAFEARRAY *pSA;
    SAFEARRAYBOUND aDim[1];
    aDim[0].lLbound= 0;
    aDim[0].cElements= cbNofData * 2;
    pSA= SafeArrayCreate( VT_VARIANT, 1, aDim );

    LPWSTR pActualData = NULL;
    SafeArrayAccessData(pSA,(void **)&pActualData);

    Come to think of it - if what you want is to pass a sequence of wide characters, why are you using SAFEARRAY in the first place? I imagive you would be better off with a BSTR.


    Igor Tandetnik

    Wednesday, July 18, 2012 4:04 PM
  • Thanks Igor Tandetnik for your reply.

    I used VT_UI1 (unsigned char) instead VT_VARIANT. It worked. Thanks a lot. 

    Thursday, July 19, 2012 10:48 AM