다음을 통해 공유


ISpRecoGrammar::SetGrammarState (Windows Embedded CE 6.0)

1/6/2010

This method sets the grammar state. See also ISpRecoGrammar::GetGrammarState.

An application can use the grammar state of a grammar object to control receipt of recognitions for rules. For example, an application might create a new object implementing ISpRecoGrammar, set the grammar state to SPGS_DISABLED, dynamically generate the rules, and finally reset the grammar state to SPGS_ENABLED when grammar construction is completed.

Syntax

HRESULT SetGrammarState(
  SPGRAMMARSTATE eGrammarState
);

Parameters

  • eGrammarState
    [in] Value indicating the state of the grammar. Possible values are defined for the SPGRAMMARSTATE enumeration. The default grammar state is SPGS_ENABLED.

Return Value

The following table shows the possible return values.

Value Description

S_OK

Function completed successfully.

E_INVALIDARG

eGrammarState is not a valid state.

FAILED(hr)

Appropriate error message.

Example

The following code snippet illustrates the use of this method to set the state of a grammar.

HRESULT hr = S_OK;
// create a new grammar object
hr = cpRecoContext->CreateGrammar(GRAM_ID, &cpRecoGrammar);
// Check hr
// disable the grammar, so that recognitions are not received
hr = cpRecoGrammar->SetGrammarState(SPGS_DISABLED);
// Check hr
// ... build the grammar ...
// activate the grammar, so applications start receiving recognitions
hr = cpRecoGrammar->SetGrammarState(SPGS_ENABLED);
// Check hr

Requirements

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

See Also

Reference

ISpRecoGrammar
SAPI Interfaces