CHMlib Logo Leading Translation Management System for Translation Agencies, Top Translation Management Software for Freelance Translators, Time Tracking Software, Word Count, Character Count and Line Count Software, Computer Assisted Translation Tool for Easy Word Count, Clipboard Character Count Software, User-Friendly Translation Memory Software, Terminology Management Software, Terminology Management Server, Microsoft Glossary Software, Dictionary of Acronyms, Social Network for Translators and Translation Agencies, Acronyms and Abbreviations Search Engine, Russian Translation Lab, Ukrainian Translation Lab.
You are reading help file online using chmlib.com
CrisisHelper - First Aid in Tough Times of World Economic Crisis


The Microsoft.com Speech website Microsoft Speech SDK

SAPI 5.1

ISpCFGInterpreter::InitGrammar

ISpCFGInterpreter_InitGrammar initializes a grammar that is loaded from an object or DLL.

When to call

InitGrammar is typically called by SAPI only when a grammar includes a rule reference (e.g., ProgId). The following grammar includes XML:

<RULEREF NAME="MyRule" OBJECT="MyObject"/>

SAPI will internally call ::CoCreateInstance on the COM object registered under the programmatic identifier (ProgId), "MyObject", and query for the ISpCFGInterpreter interface. SAPI

will call ISpCFGInterpreter::InitGrammar and pass in the string identifier "MyRule" so that the COM object's implementation can return a pointer to the compiled grammar binary (typically stored in a resource).

When to implement

Application writers and engine vendors can use the ISpCFGInterpreter interface to create COM objects that contain compiled grammars. For example, the Microsoft Speech Recognition engine (that ships in the Microsoft Speech SDK) implements inverse text normalization (INT) as a compiled SAPI context-free grammar (CFG), which is retrievable using the ISpCFGInterpreter::InitGrammar method call.

HRESULT InitGrammar(
   const WCHAR   *pszGrammarName,
   const void   **pvGrammarData
);

Parameters

pszGrammarName
[in] Address of a null-terminated string of the grammar to be loaded.
pvGrammarData
[in] Address of a pointer to the serialized binary grammar.

Return values

Value Description
S_OK Function completed successfully.
FAILED(hr) Appropriate error message.

Example

The following code snippet illustrates how an application writer or engine vendor might implement the InitGrammar method.

STDMETHODIMP CMyCFGInterpreter::InitGrammar(const WCHAR * pszGrammarName, const void ** pvGrammarData)
{
	HRESULT hr = S_OK;

	// find the resource data of type COMPILED_CFG, which has the caller's specified name
	HRSRC hResInfo = ::FindResource(_Module.GetModuleInstance(), pszGrammarName, _T("COMPILED_CFG"));
	if (hResInfo)
	{
		// Load the resource into a global handle
		HGLOBAL hData = ::LoadResource(_Module.GetModuleInstance(), hResInfo);
		if (hData)
		{
			// return/store a pointer to the compiled grammar
			*pvGrammarData = ::LockResource(hData);
			if (*pvGrammarData == NULL)
			{
				hr = HRESULT_FROM_WIN32(::GetLastError());
			}
		}
		else
		{
			hr = HRESULT_FROM_WIN32(::GetLastError());
		}
	}
	else
	{
		hr = HRESULT_FROM_WIN32(::GetLastError());
	}

	return hr;
}


You are reading help file online using chmlib.com

If you want your help file to be removed or added please send e-mail to chmlibcom@gmail.com
Partner sites: Logo Design, Simple Anti-Crisis Accounting Software, Voice Search for Web