Compartir a través de


ISpRecoGrammar::SaveCmd (Windows CE 5.0)

Send Feedback

This method allows applications using dynamic grammars to save the current grammar state to a stream.

Applications can use this method to serialize grammar changes that were made at run time for use at a later time. See also ISpRecoGrammar::LoadCmdFromMemory.

HRESULT SaveCmd(IStream* pSaveStream,WCHAR** ppCoMemErrorText);

Parameters

  • pSaveStream
    [in] Pointer to an object implementing IStream that represents the stream to which to save the compiler binary grammar.
  • ppCoMemErrorText
    [out, optional] Address of a pointer to a null-terminated string specifying error messages that occurred during the save operation.

Return Values

The following table shows the possible return values.

Value Description
S_OK Function completed successfully.
E_INVALIDARG pSaveStream is invalid or bad.
SPERR_NOT_DYNAMIC_GRAMMAR Command was loaded but compiler is not available.
SPERR_UNINITIALIZED Compiler is not available.
E_POINTER ppCoMemErrorText is invalid or bad.
FAILED(hr) Appropriate error message.

Example

The following code snippet illustrates how to use this method to serialize the CFG from one grammar object, and deserialize it into another grammar object.

HRESULT hr = S_OK;
// ... build and use a SpRecoGrammar object
// create a Win32 global stream
hr = ::CreateStreamOnHGlobal(NULL, true, &cpHStream);
// Check hr
// save the current grammar to the global stream
hr = cpRecoGrammar->SaveCmd(cpHStream, NULL);
// Check hr
// create the second grammar to deserialize into
hr = cpRecoContext->CreateGrammar(0, &cpReloadedGrammar);
// Check hr
// get a handle to the stream with the serialized grammar
::GetHGlobalFromStream(cpHStream, &hGrammar);
// Check hr
// deserialize the CFG into a new grammar object
hr = cpReloadedGrammar->LoadCmdFromMemory(
   (SPBINARYGRAMMAR*)::GlobalLock(hGrammar), SPLO_DYNAMIC);
// Check hr

Requirements

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

See Also

ISpRecoGrammar | SAPI Interfaces

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.