473,419 Members | 1,681 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,419 software developers and data experts.

ActiveX & IE interaction

I have an ActiveX control inherited from UserControl. This control is
hosted in IE(version 6 or later). How i can navigate IE from this control.
I know that i need to obtain IWebBrowser2 interface and work with it,
but i can't. Can someone show an example how to get IWebBroswer2 or way how
is possible navigate IE?
Dec 18 '06 #1
5 3693
Hi Mercdev,

Based on my understanding, you're writing an ActiveX Control using .NET
UserControl, and you want to navigate IE from this control.

As you've already known, to do this you need to obtain IWebBrowser2
interface first:

#How To Retrieve the Top-Level IWebBrowser2 Interface from an ActiveX
Control
http://support.microsoft.com/kb/257717/EN-US/

However, this doesn't work for .NET UserControl as described in following
KB:

#PRB: Cannot Retrieve Top-Level IWebBrowser2 Interface from a .NET
UserControl
http://support.microsoft.com/kb/311299/

We're sorry for any inconvenience.
Sincerely,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Dec 19 '06 #2
Thanks, but I have read this articles before. And they were not helpfull.
I have managed wrapper for IWebBrowser2.
Maybe you can provide me with some sample code how to obtain any interface,
i tried as follow:
[Guid("6d5140c1-7436-11ce-8034-00aa006009fa"), ComImport,

InterfaceType(ComInterfaceType.InterfaceIsIUnknown )]

interface IServiceProviderMy

{

IntPtr QueryService(

ref Guid guidService,

ref Guid riid,

out IntPtr pVoid);
}
class MyContorl : UserControl
{
....
public MyContorl ()
{
...
IWebBrowser2 wb = this.GetService(typeof(IWebBrowser2)) as
IWebBrowser2;
// also i've tried as:
// IWebBrowser2 wb = this.Site.GetService(typeof(IWebBrowser2)) as
IWebBrowser2;
// and
// IServiceProviderMy wb =
this.GetService(typeof(IServiceProviderMy)) as IServiceProviderMy;

...
}
....
}

All this ways didn't work.
Dec 19 '06 #3
I'll do some research and get back to you later. Thank you for your
patience and understanding.
Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Dec 19 '06 #4
Hi Mercdev,

To navigate IE from your control, you only need to obtain IWebBrowser
interface. (Let me know if you still want to get IWebBrowser2, it should be
similar)

public class SimpleControl : System.Windows.Forms.Control
{
public SimpleControl()
: base()
{
Button btn = new Button();
btn.Parent = this;
btn.Text = "Button1";
btn.Location = new Point(10, 10);
btn.Click += new EventHandler(Btn_OnClick);
Controls.Add(btn);
}

//from shlguid.h
Guid SID_STopLevelBrowser = new Guid(0x4C96BE40, 0x915C, 0x11CF, 0x99,
0xD3, 0x00, 0xAA, 0x00, 0x4A, 0xE8, 0x37);
Guid SID_SWebBrowserApp = new Guid(0x0002DF05, 0x0000, 0x0000, 0xC0,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);

private void Btn_OnClick(object sender, EventArgs e)
{
Type typeIOleObject = this.GetType().GetInterface("IOleObject",
true);
object oleClientSite = typeIOleObject.InvokeMember("GetClientSite",
BindingFlags.Instance | BindingFlags.InvokeMethod |
BindingFlags.Public,
null, this, null);

IServiceProvider serviceProvider = oleClientSite as
IServiceProvider;
Guid guidIServiceProvider = typeof(IServiceProvider).GUID;
object objIServiceProvider;
serviceProvider.QueryService(ref SID_STopLevelBrowser, ref
guidIServiceProvider, out objIServiceProvider);
serviceProvider = objIServiceProvider as IServiceProvider;
object objIWebBrowser;
Guid guidIWebBrowser = typeof(IWebBrowser).GUID;
serviceProvider.QueryService(ref SID_SWebBrowserApp, ref
guidIWebBrowser, out objIWebBrowser);
IWebBrowser webBrowser = objIWebBrowser as IWebBrowser;
MessageBox.Show(webBrowser.LocationURL);
object flags = null;
object targetFrameName = null;
object postData = null;
object headers = null;
webBrowser.Navigate("about:blank", ref flags, ref targetFrameName,
ref postData, ref headers);
}
}

[ComImport, Guid("6d5140c1-7436-11ce-8034-00aa006009fa"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown )]
public interface IServiceProvider
{
void QueryService(ref Guid guidService, ref Guid riid,
[MarshalAs(UnmanagedType.Interface)] out object ppvObject);
}

[ComImport, TypeLibType((short)0x1050),
Guid("EAB22AC1-30C1-11CF-A7EB-0000C05BAE0B")]
public interface IWebBrowser
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType =
MethodCodeType.Runtime), DispId(100)]
void GoBack();
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType =
MethodCodeType.Runtime), DispId(0x65)]
void GoForward();
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType =
MethodCodeType.Runtime), DispId(0x66)]
void GoHome();
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType =
MethodCodeType.Runtime), DispId(0x67)]
void GoSearch();
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType =
MethodCodeType.Runtime), DispId(0x68)]
void Navigate([In, MarshalAs(UnmanagedType.BStr)] string URL, [In,
Optional, MarshalAs(UnmanagedType.Struct)] ref object Flags, [In, Optional,
MarshalAs(UnmanagedType.Struct)] ref object TargetFrameName, [In, Optional,
MarshalAs(UnmanagedType.Struct)] ref object PostData, [In, Optional,
MarshalAs(UnmanagedType.Struct)] ref object Headers);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType =
MethodCodeType.Runtime), DispId(-550)]
void Refresh();
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType =
MethodCodeType.Runtime), DispId(0x69)]
void Refresh2([In, Optional, MarshalAs(UnmanagedType.Struct)] ref
object Level);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType =
MethodCodeType.Runtime), DispId(0x6a)]
void Stop();
[DispId(200)]
object Application { [return: MarshalAs(UnmanagedType.IDispatch)]
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType =
MethodCodeType.Runtime), DispId(200)] get; }
[DispId(0xc9)]
object Parent { [return: MarshalAs(UnmanagedType.IDispatch)]
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType =
MethodCodeType.Runtime), DispId(0xc9)] get; }
[DispId(0xca)]
object Container { [return: MarshalAs(UnmanagedType.IDispatch)]
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType =
MethodCodeType.Runtime), DispId(0xca)] get; }
[DispId(0xcb)]
object Document { [return: MarshalAs(UnmanagedType.IDispatch)]
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType =
MethodCodeType.Runtime), DispId(0xcb)] get; }
[DispId(0xcc)]
bool TopLevelContainer { [MethodImpl(MethodImplOptions.InternalCall,
MethodCodeType = MethodCodeType.Runtime), DispId(0xcc)] get; }
[DispId(0xcd)]
string Type { [return: MarshalAs(UnmanagedType.BStr)]
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType =
MethodCodeType.Runtime), DispId(0xcd)] get; }
[DispId(0xce)]
int Left { [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType =
MethodCodeType.Runtime), DispId(0xce)] get; [param: In]
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType =
MethodCodeType.Runtime), DispId(0xce)] set; }
[DispId(0xcf)]
int Top { [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType =
MethodCodeType.Runtime), DispId(0xcf)] get; [param: In]
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType =
MethodCodeType.Runtime), DispId(0xcf)] set; }
[DispId(0xd0)]
int Width { [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType
= MethodCodeType.Runtime), DispId(0xd0)] get; [param: In]
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType =
MethodCodeType.Runtime), DispId(0xd0)] set; }
[DispId(0xd1)]
int Height { [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType
= MethodCodeType.Runtime), DispId(0xd1)] get; [param: In]
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType =
MethodCodeType.Runtime), DispId(0xd1)] set; }
[DispId(210)]
string LocationName { [return: MarshalAs(UnmanagedType.BStr)]
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType =
MethodCodeType.Runtime), DispId(210)] get; }
[DispId(0xd3)]
string LocationURL { [return: MarshalAs(UnmanagedType.BStr)]
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType =
MethodCodeType.Runtime), DispId(0xd3)] get; }
[DispId(0xd4)]
bool Busy { [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType
= MethodCodeType.Runtime), DispId(0xd4)] get; }
}
Summary:

1) Define IServiceProvider and IWebBrowser com interface in .NET
2) When the control is hosted in IE, first try to get the IOleObject
interface, then use reflection to call GetClientSite to get the
IServiceProvider interface.

This will require UnmanagedCode and Reflection permission set.

Let me know if this works for you.

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Dec 20 '06 #5
Thank you, this is what we need!!
Dec 21 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Steven Kobes | last post by:
I have an HTML file containing some JScript that creates a "WScript.Shell" ActiveX object. When it loads, Internet Explorer says: "An ActiveX control on this page might be unsafe to interact...
11
by: Dave | last post by:
I have this sample HTML code: <html> <head> <script type="text/javascript"> var WinHttpReq = new ActiveXObject("WinHttp.WinHttpRequest.5.1"); </script> </head>
3
by: Ricky | last post by:
Hi Can anyone explain what are the relationship between COM , ActiveX, DLL ? I really get confused about the terms... Ricky
3
by: Jeffery Franzen | last post by:
Anyone know where the documentation is regarding Activex controls in asp web forms? I'm using VS.NET 2002 enterprise and am trying to use Activex controls in vb.net web form app. I do the add...
1
by: Rocio | last post by:
I have a windows app. written in VB6, now we need to expose some of its classes through a web service. I am only able to expose the classes using late binding becasue that's the way the original...
4
by: fniles | last post by:
I have an ActiveX control in my web page that I tried to access using intranet. I have implemented IObjectSafety in the ActiveX control, and when I created the CAB file using VB Pakage and...
1
by: david | last post by:
I have created an ActiveX and load it into the Component in ToolBox in the Visual Studio IDE. After create a web form project (VB.NET), I drag the activeX component into the web form design, set...
0
by: Verakso | last post by:
I have made a small interop function that uses Acrobat Distiller. It works smothly on all the XP machines, but when I try to run it on a Windows 2000,I get this error: System.Exception: Cannot...
0
by: Vijay | last post by:
Prep Courses for International Certifications, CSTE & CSQA & ISEB & ISTQB &Business Analyst & SOA Certifications in HYDERABAD. After receiving overwhelming response to our last 50+ batches, ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.