Compartir a través de


ISpGrammarBuilder::ClearRule (SAPI 5.3)

Microsoft Speech API 5.3

ISpGrammarBuilder::ClearRule

ISpGrammarBuilder::ClearRule removes all of the grammar rule information except for the rule's initial state handle.

  
    HRESULT ClearRule(
   SPSTATEHANDLE   hState
);

Parameters

  • hState
    [in] Handle to the any of the states in the grammar rule to be cleared. Only the rule's initial state handle is still valid.

Return values

Value
S_OK
E_INVALIDARG

Example

The following code snippet illustrates the use of ClearRule.

  
// Declare local identifiers:
HRESULT                       hr = S_OK;
CComPtr<ISpGrammarBuilder>    cpGrammarBuilder;
SPSTATEHANDLE                 hInit;
SPSTATEHANDLE                 hState;

hr = cpGrammarBuilder->GetRule(L"rule1", 1, 0, TRUE, &hInit;);

if (SUCCEEDED (hr))
{
  hr = cpGrammarBuilder->CreateNewState(hInit, &hState;);
}

if (SUCCEEDED (hr))
{
   hr = cpGrammarBuilder->AddWordTransition(hInit, hState, L"word", NULL, SPWT_LEXICAL, 1, NULL);
}

if (SUCCEEDED (hr))
{
   // Call ClearRule using initial state.
   hr = cpGrammarBuilder->ClearRule(hInit);
}

if (SUCCEEDED (hr))
{
   hr = cpGrammarBuilder->AddWordTransition(hInit, hState, L"word", NULL, SPWT_LEXICAL, 1, NULL);
}

if (FAILED (hr)) {}
{
   // Because hState is no longer valid.
   _ASSERT(hr == E_INVALIDARG);

   // Call ClearRule using hState != hInit.
   hr = cpGrammarBuilder->CreateNewState(hInit, &hState;);
}

if (SUCCEEDED (hr))
{
   hr = cpGrammarBuilder->AddWordTransition(hInit, hState, L"word", NULL, SPWT_LEXICAL, 1, NULL);
}

if (SUCCEEDED (hr))
{
   hr = cpGrammarBuilder->ClearRule(hState);
}

if (SUCCEEDED (hr))
{
   hr = cpGrammarBuilder->AddWordTransition(hInit, hState, L"word", NULL, SPWT_LEXICAL, 1, NULL);
}

if (FAILED (hr))
{
   // Because hState is no longer valid.
   _ASSERT(hr == E_INVALIDARG);
}