Note

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

Microsoft Speech Platform

ISpRecoGrammar::LoadCmdFromResource

ISpRecoGrammar::LoadCmdFromResource loads a context-free grammar (CFG) from a Win32 resource.

<pre IsFakePre="true" xmlns="http://www.w3.org/1999/xhtml"> <strong>HRESULT LoadCmdFromResource(</strong> <strong> HMODULE</strong> <em>hModule</em>, <strong> LPCWSTR</strong> *<em>pszResourceName</em>, <strong> LPCWSTR</strong> *<em>pszResourceType</em>, <strong> WORD</strong> <em>wLanguage</em>, <strong><a runat="server" href="jj127470(v=msdn.10).md">SPLOADOPTIONS</a></strong> <em>Options</em> <strong>);</strong> </pre>

Parameters

  • hModule
    [in] Handle to the module whose file name is being requested. If this parameter is NULL, it passes back the path for the file containing the current process.
  • pszResourceName
    [in, string] The name of the resource.
  • pszResourceType
    [in, string] The type of the resource.
  • wLanguage
    [in] The language ID.
  • Options
    [in] Flag of type SPLOADOPTIONS indicating whether the file should be loaded statically or dynamically.

Return Values

Value Description
S_OK Function completed successfully.
E_INVALIDARG Either pszResourceName or pszResourceType is invalid or bad. It may also indicate hModule could not be found. Alternatively, Options is neither SPLO_STATIC nor SPLO_DYNAMIC.
FAILED(hr) Appropriate error message.

Remarks

When an application calls ::LoadCmdFromResource, the currently loaded context-free grammar will be unloaded.

The CFG resource must be a compiled binary version of a context-free grammar.

Example

`

// Declare local identifiers:
HRESULT                      hr = S_OK;
CComPtr<ISpRecoGrammar>      cpRecoGrammar;
CComPtr<ISpRecoContext>      cpRecoContext;
HMODULE                      hModule;
ULONGLONG                    ullGramId = 1;

// Create a new grammar object. hr = cpRecoContext->CreateGrammar(ullGramId, &cpRecoGrammar;);

if (SUCCEEDED(hr)) { // Load a CFG resource named SRGRAMMAR from the current // module (hModule needs to be initialized first). hr = cpRecoGrammar->LoadCmdFromResource(hModule, (const WCHAR*)MAKEINTRESOURCE(IDC_COFFEE), L"SRGRAMMAR", ::SpGetUserDefaultUILanguage(), SPLO_STATIC); }

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

`