CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Hybrid View

  1. #1
    Join Date
    Jan 2009

    Run-Time Check Failure #2 - Stack around the variable was corrupted.

    Hi All,

    I have problem during execution of my program.
    Error is Run-Time Check Failure #2 - Stack around the variable 'pwADErrBuff' was corrupted.
    I increased variable pwADErrBuff size from 256 to 2048. But, still have problem.

    Please help me in this,

    Code Snippet is below,

    WCHAR pwErrBuff[2048];
    WCHAR pwADErrBuff[2048];
    WCHAR * pADErrCodeStr;

    pwErrBuff[0] = NULL;
    pADErrCodeStr = CrackADError( passedhr);

    int maxAlloc = sizeof(pwErrBuff)/sizeof(WCHAR);

    // If an ADSI error code was returned, display it
    if (pADErrCodeStr[0] != NULL)
    SAFE_APPEND(maxAlloc, pwErrBuff, L"<*> ADSI Error HRESULT Returns: <*> \n");
    SAFE_APPEND(maxAlloc, pwErrBuff, pADErrCodeStr);
    SAFE_APPEND(maxAlloc, pwErrBuff, L"\n");

    // Call ADsGetLastError() to retrieve the error text from ADSI
    SAFE_APPEND(maxAlloc, pwErrBuff, L"<*> ADSI Error: <*>\n");

    hr = ADsGetLastError(

    if (FAILED(hr))
    SAFE_APPEND(maxAlloc, pwErrBuff, L"<Unable to retrieve ADs Error>");
    SAFE_APPEND(maxAlloc, pwErrBuff, pwADErrBuff);

    SAFE_APPEND(maxAlloc, pwErrBuff, L"\n");

    WCHAR sz[1024];

    SAFE_APPEND(maxAlloc, pwErrBuff, L"<*> System Error: <*> \n");

    // Check the standard system to crack the bad HRESULT into a string
    if (!FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, 0, passedhr, 0, sz, 1024, 0))
    wcscat(sz, L"Unknown HRESULT error");
    SAFE_APPEND(maxAlloc, pwErrBuff, sz);

    // Display
    wprintf(L"\nERROR on %s\n\n",pwReason);
    printf("\nERROR on %X\n\n",passedhr);

  2. #2
    Join Date
    Mar 2002
    St. Petersburg, Florida, USA

    Re: Run-Time Check Failure #2 - Stack around the variable was corrupted.

    1) Please use code tags..go back and RE-READ the "BEfore you post" announcement if you have forgotten how.

    2) The code does NOT look like (but it is hard to read without code tags!) C++/CLI [aka .NET] code. If it is NOT, then this is the WRONG forum, and need to ask a moderator to MOVE your thread (do NOT crate a duplicate, it simply creates more work for the moderator, who is already VOLUNTEERING (like the rest of us) his valuable time.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)