在 C# 中实现 IShellUIHelper 时 AddFavorite 不起作用
我正在构建一个 IE 插件,我想“成为”外部对象。因此我使用 SetUIHandler 将我的类设置为 UIHandler。
我正在实现 IDocHostUIHandler (引用 Microsoft Internet Controls(COM 对象)),并在 GetExternal 中返回我的类:
public void GetExternal(out object ppDispatch)
{
ppDispatch = this;
}
这非常有效。任何其他选项我都不感兴趣,所以我需要返回 E_NOTIMPL。
例如:
public void TranslateAccelerator(ref tagMSG lpmsg, ref Guid pguidCmdGroup, uint nCmdID)
{
Marshal.ThrowExceptionForHR((int)WinAPI.HRESULT.E_NOTIMPL);
}
效果很好,但我还需要实现 IShellUIHelper (IE 期望它来自 UIHandler)。
然后当我实现添加到收藏夹时:
public void AddFavorite(string URL, ref object Title)
{
Marshal.ThrowExceptionForHR((int)WinAPI.HRESULT.E_NOTIMPL);
}
它不起作用(js 出现错误)。
当我尝试在 C++ 中执行相同操作并返回 E_NOTIMPL 作为返回值时,一切都很好:
STDMETHODIMP CMyClass::AddToFavoritesBar(BSTR URL, BSTR Title, VARIANT *Type)
{
return E_NOTIMPL;
}
我还尝试将 Marshal.ThrowExceptionForHR((int)WinAPI.HRESULT.E_NOTIMPL); 替换为
> throw new COMException("", (int)WinAPI.HRESULT.E_NOTIMPL);
但它仍然不起作用。
谁能帮我吗?
谢谢,
奥姆里
I'm building an IE addon and i want to "be" the external object. therefore i use the SetUIHandler to set my class as the UIHandler.
I'm implementing IDocHostUIHandler (referencing to Microsoft Internet Controls (COM Object)) and in GetExternal i return my class:
public void GetExternal(out object ppDispatch)
{
ppDispatch = this;
}
This works great. any other option is not interesting me so i need to return E_NOTIMPL.
for example:
public void TranslateAccelerator(ref tagMSG lpmsg, ref Guid pguidCmdGroup, uint nCmdID)
{
Marshal.ThrowExceptionForHR((int)WinAPI.HRESULT.E_NOTIMPL);
}
works great, but i need also to implement IShellUIHelper (IE expect it from the UIHandler).
and then when i implement add to favorites:
public void AddFavorite(string URL, ref object Title)
{
Marshal.ThrowExceptionForHR((int)WinAPI.HRESULT.E_NOTIMPL);
}
it don't work (the js got and error).
when i tried to do the same in C++ and return the E_NOTIMPL as return value everything works great:
STDMETHODIMP CMyClass::AddToFavoritesBar(BSTR URL, BSTR Title, VARIANT *Type)
{
return E_NOTIMPL;
}
i also tried to replace the Marshal.ThrowExceptionForHR((int)WinAPI.HRESULT.E_NOTIMPL);
with throw new COMException("", (int)WinAPI.HRESULT.E_NOTIMPL);
and it still don't work.
can anyone help me with that?
Thanks,
Omri
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将对 IShellUIHelper 和 IShellUIHelper2 成员的调用中继到 shell外部对象中的 UI 辅助对象。
Javascript 通过 IDispatch 调用外部对象的成员,因此您需要确保已正确实现 Invoke 和 GetIDsOfNames。就托管代码编程而言,这意味着您需要在类中拥有正确的方法签名,并将正确的 [DispId] 添加到您的方法中。
csexwb2 项目中有一个 IShellUIHelper 声明,您可以将其用作参考。
You need to relay calls to IShellUIHelper and IShellUIHelper2 members to the shell UI helper object in your external object.
Javascript calls the members of your external object via IDispatch, so you need to make sure you have implemented Invoke and GetIDsOfNames correctly. In terms of managed code programming, that means you need to have the right method signature in your class and add the right [DispId] to your methods.
There is a declaration of IShellUIHelper in the csexwb2 project that you can use as reference.