IDebugExpressionContext2::ParseText

Analizza un'espressione in formato testo per una valutazione successiva.

Sintassi

int ParseText(
    string                pszCode,
    enum_PARSEFLAGS       dwFlags,
    uint                  nRadix,
    out IDebugExpression2 ppExpr,
    out string            pbstrError,
    out uint              pichError
);

Parametri

pszCode
[in] Espressione da analizzare.

dwFlags
[in] Combinazione di flag dell'enumerazione PAR edizione Standard FLAGS che controlla l'analisi.

nRadix
[in] Radix da usare per analizzare le informazioni numeriche in pszCode.

ppExpr
[out] Restituisce l'oggetto IDebugExpression2 che rappresenta l'espressione analizzata, pronta per l'associazione e la valutazione.

pbstrError
[out] Restituisce il messaggio di errore se l'espressione contiene un errore.

pichError
[out] Restituisce l'indice di caratteri dell'errore in pszCode se l'espressione contiene un errore.

Valore restituito

Se ha esito positivo, restituisce S_OK; in caso contrario, restituisce un codice di errore.

Osservazioni:

Quando questo metodo viene chiamato, un motore di debug (DE) deve analizzare l'espressione e convalidarla per la correttezza. I pbstrError parametri e pichError possono essere compilati se l'espressione non è valida.

Si noti che l'espressione non viene valutata, solo analizzata. Una chiamata successiva ai metodi EvaluateSync o EvaluateAsync valuta l'espressione analizzata.

Esempio

Nell'esempio seguente viene illustrato come implementare questo metodo per un oggetto semplice CEnvBlock che espone l'interfaccia IDebugExpressionContext2 . Questo esempio considera l'espressione da analizzare come nome di una variabile di ambiente e recupera il valore da tale variabile.

HRESULT CEnvBlock::ParseText(
    LPCOLESTR           pszCode,
    PARSEFLAGS          dwFlags,
    UINT                nRadix,
    IDebugExpression2 **ppExpr,
    BSTR               *pbstrError,
    UINT               *pichError)
{
    HRESULT hr = E_OUTOFMEMORY;
    // Create an integer variable with a value equal to one plus
    // twice the length of the passed expression to be parsed.
    int iAnsiLen      = 2 * (wcslen(pszCode)) + 1;
    // Allocate a character string of the same length.
    char *pszAnsiCode = (char *) malloc(iAnsiLen);

    // Check for successful memory allocation.
    if (pszAnsiCode) {
        // Map the wide-character pszCode string to the new pszAnsiCode character string.
        WideCharToMultiByte(CP_ACP, 0, pszCode, -1, pszAnsiCode, iAnsiLen, NULL, NULL);
        // Check to see if the app can succesfully get the environment variable.
        if (GetEnv(pszAnsiCode)) {

            // Create and initialize a CExpression object.
            CComObject<CExpression> *pExpr;
            CComObject<CExpression>::CreateInstance(&pExpr);
            pExpr->Init(pszAnsiCode, this, NULL);

            // Assign the pointer to the new object to the passed argument
            // and AddRef the object.
            *ppExpr = pExpr;
            (*ppExpr)->AddRef();
            hr = S_OK;
        // If the program cannot succesfully get the environment variable.
        } else {
            // Set the errror message and return E_FAIL.
            *pbstrError = SysAllocString(L"No such environment variable.");
            hr = E_FAIL;
        }
        // Free the local character string.
        free(pszAnsiCode);
    }
    return hr;
}

Vedi anche