IDebugExpressionContext2::ParseText
如需 Visual Studio 2017 的最新文件請參閱 Visual Studio 2017 文件。
剖析文字格式,供稍後評估的運算式。
語法
HRESULT ParseText(
LPCOLESTR pszCode,
PARSEFLAGS dwFlags,
UINT nRadix,
IDebugExpression2** ppExpr,
BSTR* pbstrError,
UINT* pichError
);
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
如果運算式包含錯誤。
傳回值
如果成功,傳回S_OK
; 否則傳回錯誤碼。
備註
呼叫這個方法時,偵錯引擎 (DE) 應該剖析運算式,並驗證正確。 pbstrError
和pichError
若運算式不正確,可能會填入參數。
請注意,不會評估運算式,只能剖析。 稍後呼叫EvaluateSync或EvaluateAsync方法評估剖析的運算式。
範例
下列範例示範如何實作這種簡單的方式CEnvBlock
公開物件IDebugExpressionContext2介面。 這個範例會考慮運算式無法剖析為環境變數的名稱,並從該變數擷取值。
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;
}
另請參閱
IDebugExpressionContext2
PARSEFLAGS
IDebugExpression2
EvaluateAsync
EvaluateSync