Share via


ISpRecoGrammar::LoadCmdFromResource (SAPI 5.3)

Microsoft Speech API 5.3

ISpRecoGrammar::LoadCmdFromResource

ISpRecoGrammar::LoadCmdFromResource loads a command and control grammar from a Win32 resource.

  
    HRESULT LoadCmdFromResource(
   HMODULE         hModule,
   LPCWSTR        *pszResourceName,
   LPCWSTR        *pszResourceType,
   WORD            wLanguage,
   SPLOADOPTIONS   Options
);

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
S_OK
E_INVALIDARG
FAILED(hr)

Remarks

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

The CFG resource must be a compiled SAPI 5 binary version of a context-free grammar (see ISpGrammarCompiler::CompileStream).

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.
}