The new home for Visual Studio documentation is Visual Studio 2017 Documentation on

The latest version of this topic can be found at IDebugExpression2::EvaluateSync.

This method evaluates the expression synchronously.

int EvaluateSync(  
   enum_EVALFLAGS       dwFlags,   
   uint                 dwTimeout,   
   IDebugEventCallback2 pExprCallback,   
   out IDebugProperty2  ppResult  


[in] A combination of flags from the EVALFLAGS enumeration that control expression evaluation.

[in] Maximum time, in milliseconds, to wait before returning from this method. Use INFINITE to wait indefinitely.

[in]This parameter is always a null value.

[out] Returns the IDebugProperty2 object that contains the result of the expression evaluation.

If successful, returns S_OK; otherwise returns an error code. Some typical error codes are:

E_EVALUATE_BUSY_WITH_EVALUATIONAnother expression is currently being evaluated, and simultaneous expression evaluation is not supported.
E_EVALUATE_TIMEOUTEvaluation timed out.

For synchronous evaluation, it is not necessary to send an event back to Visual Studio upon completion of the evaluation.

The following example shows how to implement this method for a simple CExpression object that implements the IDebugExpression2 interface.

HRESULT CExpression::EvaluateSync(EVALFLAGS dwFlags,  
                                  DWORD dwTimeout,  
                                  IDebugEventCallback2* pExprCallback,  
                                  IDebugProperty2** ppResult)  
    // Set the aborted state to FALSE.    
    m_bAborted = FALSE;    
    // Delegate the evaluation to EvalExpression.    
    return EvalExpression(TRUE, ppResult);    
HRESULT CExpression::EvalExpression(BOOL bSynchronous,  
                                    IDebugProperty2** ppResult)  
    HRESULT hr;  
    // Get the value of an environment variable.  
    PCSTR pszVal = m_pEnvBlock->GetEnv(m_pszVarName);  
    // Create and initialize a CEnvVar object with the retrieved value.  
    // CEnvVar implements the IDebugProperty2 interface.  
    CComObject<CEnvVar> *pEnvVar;  
    pEnvVar->Init(m_pszVarName, pszVal, m_pDoc);  
    if (pszVal) {  
        // Check for synchronous evaluation.  
        if (bSynchronous) {  
            // Set and AddRef the result, IDebugProperty2 interface.  
            *ppResult = pEnvVar;  
            hr = S_OK;  
        } else {  
            //For asynchronous evaluation, send an evaluation complete event.  
            CExprEvalEvent *pExprEvent = new CExprEvalEvent(this, pEnvVar);  
            pExprEvent->SendEvent(m_pExprCallback, NULL, NULL, NULL);  
    } else {  
        // If a valid value is not retrieved, return E_FAIL.  
        hr = E_FAIL;  
    return hr;