Share via


ISpGrammarBuilder::ClearRule

Other versions of this page are also available for the following:

Windows Mobile Not SupportedWindows Embedded CE Supported

8/28/2008

This method removes all grammar rule structural information (states and transitions) except for the handle to the initial state of the rule.

Syntax

HRESULT ClearRule(
  SPSTATEHANDLE hState
);

Parameters

  • hState
    [in] Handle to any of the states in the grammar rule to clear. All but the initial state handle are no longer valid.

Example

The following code example illustrates the use of this method.

HRESULT hr = S_OK;
SPSTATEHANDLE hInit;
SPSTATEHANDLE hState;
hr = pGrammarBuilder->GetRule(L"rule1", 1, 0, TRUE, &hInit);
// ClearRule using hInitState.
hr = pGrammarBuilder->CreateNewState(hInit, &hState);
hr = pGrammarBuilder->AddWordTransition(hInit, hState, L"word", NULL,
  SPWT_LEXICAL, 1, NULL);
hr = pGrammarBuilder->ClearRule(hInit);
// Check hr.
hr = pGrammarBuilder->AddWordTransition(hInit, hState, L"word", NULL,
  SPWT_LEXICAL, 1, NULL);
// E_INVALIDARG because hState is no longer valid.
// ClearRule using hState != hInit.
hr = pGrammarBuilder->CreateNewState(hInit, &hState);
hr = pGrammarBuilder->AddWordTransition(hInit, hState, L"word", NULL,
  SPWT_LEXICAL, 1, NULL);
hr = pGrammarBuilder->ClearRule(hState);
// Check hr.
hr = pGrammarBuilder->AddWordTransition(hInit, hState, L"word", NULL,
  SPWT_LEXICAL, 1, NULL);
// E_INVALIDARG because hState is no longer valid.

Return Value

The following table shows the possible return values.

Value Description

S_OK

Function completed successfully.

E_INVALIDARG

Value specified in hState is not valid.

Requirements

Header sapi.h, sapi.idl
Library sapilib.lib
Windows Embedded CE Windows CE .NET 4.1 and later

See Also

Reference

ISpGrammarBuilder
SAPI Interfaces