Hi
In our web application we want to access frames in HTA.But some reason ,HTA doesn t seems to load the application.So now we trying for BHO in VJ#.But we don t have a clear idea ,whether it is supported by vj# or not.If any body have idea in it ,revert with some examples.
thanks
praveen

Does Visual J# supports Browser Helper Objects(BHO)
natanz
Hi Praveen,
I just changed the DocumentCompleteEventHandler to DownloadCompleteEventHandler. DownloadCompleteEventHandler doest not use /**@ref*/. I am pasting the changed code. Hope this will work for you.
import
System.*;import
System.Collections.Generic.*;import
System.Text.*;import
System.Runtime.InteropServices.*;import
Microsoft.Win32.*;import
mshtml.*;import
SHDocVw.*;/**@attribute ComVisible(true),ClassInterfaceAttribute(ClassInterfaceType.None),GuidAttribute("D5423C28-959D-4909-BB9B-431286B62483")*/
public
class samplebho implements IObjectWithSite{
WebBrowser browser;
#region
IObjectWithSite Members public void SetSite(Object site){
if (site == null){
browser.add_DownloadComplete(
new DWebBrowserEvents2_DownloadCompleteEventHandler(this.browser_DownloadComplete));browser =
null;}
else{
browser = (WebBrowser)site;
browser.add_DownloadComplete(
new DWebBrowserEvents2_DownloadCompleteEventHandler(this.browser_DownloadComplete));}
return;}
public void GetSite(/**@ref */ Guid guid, Object ppvSite){
ppvSite = browser;
return;}
#endregion
#region
events //private void browser_DownloadComplete(Object pDisp, /**@ref */ Object URL) private void browser_DownloadComplete(){
//HTMLDocumentClass doc = (HTMLDocumentClass)browser.get_Document(); //System.Windows.Forms.MessageBox.Show("Page size is "+ doc.get_fileSize().toString());System.Windows.Forms.MessageBox.Show("Download completed");
}
#endregion
#region
registry commands /**@attribute ComRegisterFunction()*/ public static void RegisterBHO(Type t){
RegistryKey rk = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Browser Helper Objects",
true);rk.CreateSubKey("{" + t.get_GUID().ToString() + "}");
}
/**@attribute ComUnregisterFunction()*/ public static void UnregisterBHO(Type t){
RegistryKey rk = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Browser Helper Objects",
true);rk.DeleteSubKey("{" + t.get_GUID().ToString() + "}");
}
#endregion
}
#region
interfaces /**@attribute ComImportAttribute()*/ /**@attribute InterfaceType(ComInterfaceType.InterfaceIsIUnknown)*/ /**@attribute GuidAttribute("FC4801A3-2BA9-11CF-A229-00AA003D7352")*/public
interface IObjectWithSite{
void SetSite(/** @attribute MarshalAsAttribute(UnmanagedType.IUnknown)*/ Object pUnkSite); void GetSite(/**@ref */ Guid riid, /** @attribute MarshalAsAttribute(UnmanagedType.IUnknown)*/ Object ppvSite);}
#endregion
wundrlik
Hi Praveen ,
All BHO application should implement the following interface.
public interface IObjectWithSite
{
void SetSite(/** @attribute MarshalAsAttribute(UnmanagedType.IUnknown)*/ Object pUnkSite);
void GetSite(/**@ref */ Guid riid, /** @attribute MarshalAsAttribute(UnmanagedType.IUnknown)*/ Object ppvSite);
}
In the above interface GetSite function expects " /**@ref */ Guid riid " as argument.
The reason for the ie crash is @ref is not supported in VJ# 2003. It will work fine in VJ# 2005.
So I suspect that this scenario is not supported in VJ# 2003.
Thanks,
Noorul Ameen.
AJNothing82
Hi Praveen,
For this error D:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\sample\samplebho.jsl(77,0): error VJS1220: Cannot resolve name 'System.Windows.Forms.MessageBox'
Please reference System.windows.forms.dll.
Reason for the remaining error is /**ref*/ is not supported in VJ# 2003. The same code works fine VJ#2005. Pass by reference is not supported VJ# 2003.
I will suggest to use VJ# 2005.
Thanks,
Noorul Ameen.
Damodar Periwal
i have done as u told but it doesnot throw any message box after it have loaded any page.Thanks for ur support by providing useful guidelines in this conversation.
regards
praveen
Jacob Mathew
Whether it is possible to implement the codes in vj#2003 to work.But not your example code that you gave,instead a new code that can work in VJ 2003 also.
If so what are modifications that needs to changed.
thanks
Praveen
Gregor Jovan
Hi Praveen,
BHO is supported in VJ#. I have done a small example.
Create a new VJ# classlibrary project named sample.Add reference to the folllowing dlls from visual studio IDE.
C:\Program Files\Microsoft.NET\Primary Interop Assemblies\Microsoft.mshtml.dll
C:\Windows\System32\shdocvw.dll
copy the following code and paste it class1.jsl
Compile the project. the sample.dll will be in bin/debug folder.
Register the sample.dll using regasm /codebase sample.dll from visual studio commandpromt.
now open some website and message box will show the size of the page.
To unregister the sample.dll use regasm /unregister sample.dll
import System.*;
import
System.Collections.Generic.*;import
System.Text.*;import
System.Runtime.InteropServices.*;import
Microsoft.Win32.*;import
mshtml.*;import
SHDocVw.*;/**@attribute ComVisible(true),ClassInterfaceAttribute(ClassInterfaceType.None),GuidAttribute("D5423C28-959D-4909-BB9B-431286B62483")*/
public
class samplebho implements IObjectWithSite{
WebBrowser browser;#region
IObjectWithSite Members public void SetSite(Object site){
if (site == null){
browser.add_DocumentComplete(
new DWebBrowserEvents2_DocumentCompleteEventHandler(this.browser_DocumentComplete));browser =
null;}
else{
browser = (
WebBrowser)site;browser.add_DocumentComplete(
new DWebBrowserEvents2_DocumentCompleteEventHandler(browser_DocumentComplete));}
return;}
public void GetSite(/**@ref */ Guid guid, Object ppvSite){
ppvSite = browser;
return;}
#endregion
#region
events void browser_DocumentComplete(Object pDisp, /**@ref */ Object URL){
HTMLDocumentClass doc = (HTMLDocumentClass)browser.get_Document(); System.Windows.Forms.MessageBox.Show("Page size is "+ doc.get_fileSize().toString());}
#endregion
#region
registry commands /**@attribute ComRegisterFunction()*/ public static void RegisterBHO(Type t){
RegistryKey rk = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Browser Helper Objects", true);rk.CreateSubKey(
"{" + t.get_GUID().ToString() + "}");}
/**@attribute ComUnregisterFunction()*/ public static void UnregisterBHO(Type t){
RegistryKey rk = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Browser Helper Objects", true);rk.DeleteSubKey(
"{" + t.get_GUID().ToString() + "}");}
#endregion
}
#region
interfaces/**@attribute ComImportAttribute()*/
/**@attribute InterfaceType(ComInterfaceType.InterfaceIsIUnknown)*/
/**@attribute GuidAttribute("FC4801A3-2BA9-11CF-A229-00AA003D7352")*/
public
interface IObjectWithSite{
void SetSite(/** @attribute MarshalAsAttribute(UnmanagedType.IUnknown)*/ Object pUnkSite); void GetSite(/**@ref */ Guid riid, /** @attribute MarshalAsAttribute(UnmanagedType.IUnknown)*/ Object ppvSite);}
#endregion
For more information on BHO visit http://msdn.microsoft.com/library/default.asp url=/library/en-us/dnwebgen/html/bho.asp
Thanks,
Noorul Ameen.
Baruchf
Now the code gets compiled without any error and i am able to sign the dll and registered it using regasm.But when i open the Internet Explorer,it crashes displaying
"Internet Explorer has encountered a problem and needs to close. We are sorry for the inconvenience."
I am using IE version 6 sp2.
After that i register the assembly with strong name.exe and it also loads and IE opens as usual.BUt no output is seen.
Could u tell what would be the ouput ,when opening the IE.Since i did not see any kind of it.
Thanks
Praveen
Jamie Hornstein
thanks for the code that u sent in vj#.The thing now is,it throws some error during building the project. The errors are
D:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\sample\samplebho.jsl(35,29): error VJS1425: Signature of method 'browser_DocumentComplete' doesn't match with the signature of 'SHDocVw.DWebBrowserEvents2_DocumentCompleteEventHandler' Delegate
D:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\sample\samplebho.jsl(47,29): error VJS1425: Signature of method 'browser_DocumentComplete' doesn't match with the signature of 'SHDocVw.DWebBrowserEvents2_DocumentCompleteEventHandler' Delegate
D:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\sample\samplebho.jsl(77,0): error VJS1220: Cannot resolve name 'System.Windows.Forms.MessageBox'
D:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\sample\samplebho.jsl(75,0): warning VJS1512: Variable 'doc' is initialized but never used
Build complete -- 3 errors, 1 warnings
Building satellite assemblies...
Satellite assemblies could not be built because the main project output is missing.
i have also added both the reference shdoccvw.dll and microsoft.mshtml.dll.Besides whether any other reference should be made or not to build sucessfully.
thanks
praveen
amou
Hi,
After registering the dll go to any one of the website (ex-www.yahoo.com) after the page downloaded completely, a message box will appear with the message "Download completed".
Thanks,
Noorul Ameen.