473,785 Members | 2,209 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3722
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(C omInterfaceType .InterfaceIsIUn known)]

interface IServiceProvide rMy

{

IntPtr QueryService(

ref Guid guidService,

ref Guid riid,

out IntPtr pVoid);
}
class MyContorl : UserControl
{
....
public MyContorl ()
{
...
IWebBrowser2 wb = this.GetService (typeof(IWebBro wser2)) as
IWebBrowser2;
// also i've tried as:
// IWebBrowser2 wb = this.Site.GetSe rvice(typeof(IW ebBrowser2)) as
IWebBrowser2;
// and
// IServiceProvide rMy wb =
this.GetService (typeof(IServic eProviderMy)) as IServiceProvide rMy;

...
}
....
}

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(Bt n_OnClick);
Controls.Add(bt n);
}

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

private void Btn_OnClick(obj ect sender, EventArgs e)
{
Type typeIOleObject = this.GetType(). GetInterface("I OleObject",
true);
object oleClientSite = typeIOleObject. InvokeMember("G etClientSite",
BindingFlags.In stance | BindingFlags.In vokeMethod |
BindingFlags.Pu blic,
null, this, null);

IServiceProvide r serviceProvider = oleClientSite as
IServiceProvide r;
Guid guidIServicePro vider = typeof(IService Provider).GUID;
object objIServiceProv ider;
serviceProvider .QueryService(r ef SID_STopLevelBr owser, ref
guidIServicePro vider, out objIServiceProv ider);
serviceProvider = objIServiceProv ider as IServiceProvide r;
object objIWebBrowser;
Guid guidIWebBrowser = typeof(IWebBrow ser).GUID;
serviceProvider .QueryService(r ef SID_SWebBrowser App, ref
guidIWebBrowser , out objIWebBrowser) ;
IWebBrowser webBrowser = objIWebBrowser as IWebBrowser;
MessageBox.Show (webBrowser.Loc ationURL);
object flags = null;
object targetFrameName = null;
object postData = null;
object headers = null;
webBrowser.Navi gate("about:bla nk", ref flags, ref targetFrameName ,
ref postData, ref headers);
}
}

[ComImport, Guid("6d5140c1-7436-11ce-8034-00aa006009fa"),
InterfaceType(C omInterfaceType .InterfaceIsIUn known)]
public interface IServiceProvide r
{
void QueryService(re f Guid guidService, ref Guid riid,
[MarshalAs(Unman agedType.Interf ace)] out object ppvObject);
}

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

1) Define IServiceProvide r 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
IServiceProvide r 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
14468
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 with other parts of the page. Do you want to allow this interaction?" I would like to suppress this message, but even when I set all ActiveX-related security settings to "Enable", it still appears.
11
3648
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
2267
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
2521
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 control to pallete and then add a reference. I get the interop dll added to bin folder. I did this with the MediaPlayer activex control as a simple case to to try and get it working. I set the control to autostart via the html parameter tag for...
1
15652
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 VB6 was written. I ahve already exposed some of the original classes, and they work fine. Now, I added a new ActiveX component to the windows app (in vb6). I am able to call it by late binding from within the vb6 app. itself, and from a dummy vbs...
4
23371
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 Deployment Wizard, under "Safety Settings" I selected "Yes" for "Safe for Scripting" and "Yes" for "Safe for Initialization". I also have signed the CAB file. In IE, the option 'Script ActiveX controls marked Safe for Scripting' is already set to...
1
2018
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 ID and name for it in the property, and the HTML looks like: <OBJECT id="AxCarControlID" style="Z-INDEX: 101; LEFT: 56px; WIDTH: 616px; POSITION: absolute; TOP: 304px; HEIGHT: 120px" classid="clsid:65A0EEC0-745F-11D3-B92E-0020781238D4"...
0
1241
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 create ActiveX component. at Microsoft.VisualBasic.Interaction.CreateObject(String ProgId, String ServerName) at MediaBuilder.Utils.PDFCreator.PDFCreator.Main(String args) in C: \Visual Studio Projects\Utilities\PDFCreator\Main.cs:line 31
0
6746
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, SPECTRAMIND SOLUTIONS now announces a new batch of Prep Courses for CSQA & CSTE& ISEB & ISTQB & Business Analyst & SOA so as to prepare you thoroughly for the most prestigious certification exams conducted by International organizations. We...
0
9646
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9484
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10157
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9957
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8983
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7505
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6742
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5518
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.