Share via


Note

Please see Azure Cognitive Services for Speech documentation for the latest supported speech solutions.

Microsoft Speech Platform

ISpRecoGrammar::LoadCmdFromMemory

ISpRecoGrammar::LoadCmdFromMemory loads a compiled binary version of a context-free grammar (CFG) from memory.

<pre IsFakePre="true" xmlns="http://www.w3.org/1999/xhtml"> <strong>HRESULT LoadCmdFromMemory(</strong> <strong>const</strong> <a runat="server" href="jj127867(v=msdn.10).md"><strong>SPBINARYGRAMMAR</strong></a> *<em>pBinaryData</em>, <a runat="server" href="jj127470(v=msdn.10).md"><strong>SPLOADOPTIONS</strong></a> <em>Options</em> <strong>);</strong> </pre>

Parameters

  • pBinaryData
    [in] The serialized header buffer of type SPBINARYGRAMMAR.
  • Options
    [in] Flag of type SPLOADOPTIONS indicating whether the file should be loaded statically or dynamically.

Remarks

When an application calls ::LoadCmdFromMemory, the currently loaded CFG will be unloaded.

Return Values

Value Description
S_OK Function completed successfully.
E_INVALIDARG Either pBinaryData or one of its members is invalid or bad. It may also indicate pBinaryData->FormatId is not SPGDF_ContextFree. Alternatively, Options is neither SPLO_STATIC nor SPLO_DYNAMIC.
FAILED(hr) Appropriate error message.

Example

The following code snippet illustrates how to use ISpRecoGrammar::LoadCmdFromMemory to serialize the CFG from one SpRecoGrammar object and deserialize it into another SpRecoGrammar object.

`

// Declare local identifiers:
HRESULT                      hr = S_OK;
CComPtr<ISpRecoGrammar>      cpRecoGrammar;
CComPtr<ISpRecoGrammar>      cpReloadedGrammar;
CComPtr<ISpRecoContext>      cpRecoContext;
CComPtr<IStream>             cpHStream;
HGLOBAL                      hGrammar;

// Build and use a SpRecoGrammar object...

// Create a Win32 global stream. hr = ::CreateStreamOnHGlobal(NULL, true, &cpHStream;);

if (SUCCEEDED(hr)) { // Save the current grammar to the global stream. hr = cpRecoGrammar->SaveCmd(cpHStream, NULL); }

if (SUCCEEDED(hr)) { // Create the second grammar to deserialize into. hr = cpRecoContext->CreateGrammar(0, &cpReloadedGrammar;); }

if (SUCCEEDED(hr)) { // Get a handle to the stream with the serialized grammar. ::GetHGlobalFromStream(cpHStream, &hGrammar;); }

// Deserialize the CFG into a new grammar object. hr = cpReloadedGrammar->LoadCmdFromMemory((SPBINARYGRAMMAR *)::GlobalLock(hGrammar), SPLO_DYNAMIC);

if (SUCCEEDED(hr)) { // Do stuff here. }

`