tButton temb = new tButton(); ITfLangBarItemMgr pLangBarItemMgr = threadMgr as…
- User
tButton temb = new tButton(); ITfLangBarItemMgr pLangBarItemMgr = _threadMgr as ITfLangBarItemMgr; if (pLangBarItemMgr == null) return new HRESULT() { Code = (int)ManagerReturnValues.TF_E_FAIL }; HRESULT hr = pLangBarItemMgr.AddItem(temb);
以上代码中pLangBarItemMgr.AddItem执行AddItem方法时,返回E_FAIL错误,请分析怎么改错
已知tButton 是一个ITfLangBarItemButton接口的实现,声明如下: [ComVisible(true)] [ClassInterface(ClassInterfaceType.None)] [ComDefaultInterface(typeof(ITfLangBarItemButton))] internal class tButton: ITfLangBarItemButton { public HRESULT GetInfo([Out] out TF_LANGBARITEMINFO pInfo) {
pInfo=new TF_LANGBARITEMINFO(); pInfo.clsidService = SaywolInputTextService.CLSID_TEXTSERVICE; pInfo.guidItem = SaywolInputTextService.GUID_LBI_INPUTMODE;//从Windows 8开始,此值应GUID_LBI_INPUTMODE (或语言栏项将被忽略) 。 pInfo.dwStyle = TF_LBI_STYLE.TF_LBI_STYLE_BTN_BUTTON | TF_LBI_STYLE.TF_LBI_STYLE_BTN_MENU;// pInfo.ulSort = 0;
pInfo.szDescription = “TSF Input Method”;
return new HRESULT() { Code = 0 }; }
public HRESULT GetStatus([Out] out TF_LBI_STATUS pdwStatus) { pdwStatus= TF_LBI_STATUS.TF_LBI_STATUS_HIDDEN; return new HRESULT() { Code = 0 }; }
public HRESULT Show([In] bool fShow) { return new HRESULT() { Code = 0 }; }
public HRESULT GetTooltipString([MarshalAs(UnmanagedType.BStr), Out] out string pbstrToolTip) { pbstrToolTip = “测试”; return new HRESULT() { Code = 0 }; }
public HRESULT OnClick([In] TfLBIClick click, [In] POINT pt, [In] ref RECT prcArea) { return new HRESULT() { Code = 0 }; }
public HRESULT InitMenu([In, MarshalAs(UnmanagedType.Interface)] ITfMenu pMenu) { return new HRESULT() { Code = 0 }; }
public HRESULT OnMenuSelect([In] uint wID) { return new HRESULT() { Code = 0 }; }
public HRESULT GetIcon([Out] out IntPtr phIcon) { phIcon=IntPtr.Zero; return new HRESULT() { Code = 0 }; }
public HRESULT GetText([MarshalAs(UnmanagedType.BStr), Out] out string pbstrText) { pbstrText = “测试”; return new HRESULT() { Code = 0 }; }
public void OnClick(TfLBIClick click, Point pt, int position, int menuId, ITfMenu menu) { throw new NotImplementedException(); }
void ITfLangBarItemButton.InitMenu(ITfMenu menu) { throw new NotImplementedException(); }
public bool IsEnabled() { throw new NotImplementedException(); }
public bool IsChecked() { throw new NotImplementedException(); }
public void OnUpdate(TfLBIClick click, Point pt, int position, int menuId, ITfMenu menu) { throw new NotImplementedException(); }
[return: MarshalAs(UnmanagedType.Struct)] public TF_DISPLAYATTRIBUTE GetInfo() { throw new NotImplementedException(); } }
- Assistant
可能的原因是tButton类没有正确实现ITfLangBarItem接口中的所有方法。建议将所有未实现的方法在类中实现,并确保返回值正确。如果仍然存在问题,可以进一步检查代码并查看日志以确定问题所在。