ISpRecoContext::CreateGrammar

This method creates a grammar.

HRESULT CreateGrammar(
  ULONGLONG ullGrammarId,
  ISpRecoGrammar** ppGrammar
);

Parameters

  • ullGrammarId
    [in] Grammar identifier. The identifier is used by the application and is not required. This identifier is associated with all result objects from the grammar, as defined by an SPPHRASE structure (ullGrammarID member).
  • ppGrammar
    [out] Address of a pointer to an object implementing ISpRecoGrammar. The application must call IUnknown::Release on the object when finished using it.

Return Values

The following table shows the possible return values.

Value Description
S_OK Function completed successfully.
E_POINTER ppGrammar is invalid.
E_OUTOFMEMORY Not enough system memory to create a grammar object.
SPERR_SR_ENGINE_EXCEPTION An exception was thrown by the SR engine during OnCreateGrammar.
FAILED(hr) Appropriate error message.

Example

The following code snippet illustrates the use of this method.

HRESULT hr = S_OK;
hr = cpRecoContext->CreateGrammar(GRAM_ID, &cpRecoGrammar);
// Check hr
// load a cfg from a file
hr = cpRecoGrammar->LoadCmdFromFile(MY_CFG_FILENAME, SPLO_STATIC);
// Check hr
// start the top-level rules
hr = cpRecoGrammar->SetRuleState(NULL, NULL, SPRS_ACTIVE);
// Check hr
// get a recognition
// ...
// get the recognized phrase from the recognition result object
hr = cpRecoResult->GetPhrase(&pPhrase);
// Check hr
// check the grammar identifier of the recognition result
SPDBG_ASSERT(GRAM_ID == pPhrase->ullGrammarID);

Requirements

OS Versions: Windows CE .NET 4.1 and later.
Header: Sapi.h, Sapi.idl.
Link Library: Sapilib.lib.

See Also

ISpRecoContext | SAPI Interfaces

 Last updated on Saturday, April 10, 2004

© 1992-2003 Microsoft Corporation. All rights reserved.