I tried to use IspObjectToken::DisplayUI from SAPI 5.4 in C# and I don't know what are the exact parameters for that.
void ISpObjectToken.DisplayUI(ref _RemotableHandle HWndParent, string pszTitle, string pszTypeOfUI,IntPtr pvExtraData, uint cbExtraData,object punkObject)
I know that we should put null for pszTitle
, and for pszTypeOfUI
we should use one of supported UI like MicTraining
or AddRemoveWord
, But I know nothing about the rest of it. I'm using windows 7 on my laptop.
Edit: This is the code that I wrote and obviously it's not working.
private void button1_Click(object sender, EventArgs e)
{
int pfSupported;
string extradata = "test\0";
IntPtr pvExtraData = Marshal.StringToHGlobalUni(extradata);
uint cbExtraData = (uint)extradata.Length * sizeof(Char);
Speechlib._RemotableHandle rh = new Speechlib._RemotableHandle();
rh = getRemotableHandle(this.Handle);
ISpObjectToken isot = (ISpObjectToken)new SpObjectToken();
isot.IsUISupported("AddRemoveWord", pvExtraData, cbExtraData, null, out pfSupported);
if (pfSupported == 1)
{
isot.DisplayUI(ref rh, null, "AddRemoveWord", pvExtraData, cbExtraData, null);
}
}
SpeechLib._RemotableHandle getRemotableHandle(IntPtr handle)
{
IntPtr address = Marshal.AllocHGlobal(IntPtr.Size);
Marshal.WriteIntPtr(address, handle);
return (SpeechLib._RemotableHandle)Marshal.PtrToStructure(address, typeof(SpeechLib._RemotableHandle));
}
You can always pass nulls and 0 (as appropriate) to get the default behavior for the type of UI.
If you want specific behavior, then what you pass depends on the type of UI, and on the underlying engine.
For the Microsoft Desktop SR engine, the pUnkObject parameter should always be NULL. There are no (interesting) valid non-null values for this parameter. pvExtraData and cbExtraData can be non-NULL if pszTypeOfUI is either SPDUI_UserTraining or SPDUI_AddRemoveWord.
When pszTypeOfUI is SPDUI_AddRemoveWord, then pvExtraData can be a standard null-terminated string containing the word to add to the lexicon. cbExtraData should be the size of the string in bytes, including the terminating null.
When pszTypeOfUI is SPDUI_UserTraining, then pvExtraData should be a double-null-terminated string containing a set of training sentences. cbExtraData should be the size of the entire string in bytes, including both terminating nulls.
I go into a bit more detail on my blog.