IDebugExpressionContext2::ParseText
나중에 계산을 위해 식을 텍스트 형식으로 구문 분석합니다.
구문
int ParseText(
string pszCode,
enum_PARSEFLAGS dwFlags,
uint nRadix,
out IDebugExpression2 ppExpr,
out string pbstrError,
out uint pichError
);
매개 변수
pszCode
[in] 구문 분석할 식입니다.
dwFlags
[in] 구문 분석을 제어하는 PARSEFLAGS 열거형의 플래그 조합입니다.
nRadix
[in] pszCode
에서 숫자 정보를 구문 분석하는 데 사용할 기수입니다.
ppExpr
[out] 바인딩 및 계산할 준비가 된 구문 분석된 식을 나타내는 IDebugExpression2 개체를 반환합니다.
pbstrError
[out] 식에 오류가 있는 경우 오류 메시지를 반환합니다.
pichError
[out] 식에 오류가 있는 경우 pszCode
에서 오류의 문자 인덱스를 반환합니다.
Return Value
성공하면 S_OK
를 반환하고, 실패하면 오류 코드를 반환합니다.
설명
이 메서드가 호출되면 DE(디버그 엔진)는 식을 구문 분석하고 정확성을 검증해야 합니다. 식이 잘못된 경우 pbstrError
및 pichError
매개 변수가 채워질 수 있습니다.
식은 계산하지 않고 구문 분석만 합니다. 나중에 EvaluateSync 또는 EvaluateAsync 메서드 호출이 구문 분석된 식을 계산합니다.
예시
다음 예제에서는 IDebugExpressionContext2 인터페이스를 노출하는 간단한 CEnvBlock
개체에 대해 이 메서드를 구현하는 방법을 보여 줍니다. 이 예제에서는 식을 환경 변수의 이름으로 구문 분석하고 해당 변수에서 값을 검색합니다.
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 successfully 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 successfully 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;
}