2011-10-18 16 views
0

我正在構建一個IE插件,我想「是」外部對象。因此我使用SetUIHandler將我的類設置爲UIHandler。AddFavorite在c#中實現IShellUIHelper時不工作#

我執行的IDocHostUIHandler(引用到Microsoft Internet控件(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; 
} 

我也試圖與throw new COMException("", (int)WinAPI.HRESULT.E_NOTIMPL);更換Marshal.ThrowExceptionForHR((int)WinAPI.HRESULT.E_NOTIMPL);,它仍然不起作用。

任何人都可以幫助我嗎?

感謝,

歐米

+0

拋出NotImplementException,它將轉換爲E_NOTIMPL。 –

+0

這不起作用 – Omri

回答

1

你需要在外部對象中繼到IShellUIHelper和IShellUIHelper2成員對shell UI helper object電話。

Javascript通過IDispatch調用外部對象的成員,因此您需要確保已經正確實現了Invoke和GetIDsOfNames。就託管代碼編程而言,這意味着您需要在您的類中擁有正確的方法簽名,並將正確的[DispId]添加到您的方法中。

csexwb2 project中有一個IShellUIHelper聲明,您可以將其用作參考。

+0

謝謝生病嘗試 – Omri