Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 112679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:34:57+00:00 2026-05-11T02:34:57+00:00

In my last development environment, I was able to easily interact with COM, calling

  • 0

In my last development environment, I was able to easily interact with COM, calling methods on COM objects. Here is the original code, translated into C# style code (to mask the original language):

public static void SpawnIEWithSource(String szSourceHTML) {     OleVariant ie; //IWebBrowser2     OleVariant ie = new InternetExplorer();     ie.Navigate2('about:blank');      OleVariant webDocument = ie.Document;     webDocument.Write(szSourceHTML);     webDocument.close;      ie.Visible = True; } 

Now begins the tedious, painful, process of trying to interop with COM from managed code.

PInvoke.net already contains the IWebBrower2 translation, the relavent porition of which is:

[ComImport,     DefaultMember('Name'),     Guid('D30C1661-CDAF-11D0-8A3E-00C04FC9E26E'),     InterfaceType(ComInterfaceType.InterfaceIsIDispatch),     SuppressUnmanagedCodeSecurity] public interface IWebBrowser2 {     [DispId(500)]     void Navigate2([In] ref object URL, [In] ref object Flags, [In] ref object TargetFrameName, [In] ref object PostData, [In] ref object Headers);      object Document { [return: MarshalAs(UnmanagedType.IDispatch)] [DispId(0xcb)] get; } } 

I’ve created the COM class:

[ComImport] [Guid('0002DF01-0000-0000-C000-000000000046')] public class InternetExplorer { } 

So now it’s time for my actual C# transaction:

public static void SpawnIEWithSource(String szHtml) {     PInvoke.ShellDocView.IWebBrowser2 ie;     ie = (PInvoke.ShellDocView.IWebBrowser2)new PInvoke.ShellDocView.InternetExplorer();      //Navigate to about:blank to initialize the browser     object o = System.Reflection.Missing.Value;     String url = @'about:blank';     ie.Navigate2(ref url, ref o, ref o, ref o, ref o);      //stuff contents into the document     object webDocument = ie.Document;     //webDocument.Write(szHtml);     //webDocument.Close();      ie.Visible = true; } 

The careful readers notice that IWebBrowser2.Document is a late-bound IDispatch. We’re using Visual Studio 2005, with .NET 2.0 on our, and our customer’s, machines.

So what’s the .NET 2.0 method to invoke methods on an object that, on some level, only supports late-bound IDispatch?

A quick search of Stack Overflow for using IDispatch from C# turns up this post saying what I want is not possible in .NET.

So is it possible to use COM from C# .NET 2.0?


The question is that there is an accepted design pattern that I want to use in C#/.NET. It involves launching Internet Explorer out of process, and giving it HTML content, all the while not using temporary files.

A rejected design idea is hosting Internet Explorer on a WinForm.

An acceptable alternative is launching the system registered web browser, giving it HTML to display, without using a temporary file.

The stumbling block is continuing to use COM objects in the .NET world. The specific problem involves performing late-binding calls to IDispatch without needing C# 4.0. (i.e. while using .NET 2.0)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T02:34:58+00:00Added an answer on May 11, 2026 at 2:34 am

    Late bound IDispatch called is relativly easy in .NET, although piss-poor:

    public static void SpawnIEWithSource(String szHtml) {     // Get the class type and instantiate Internet Explorer.     Type ieType = Type.GetTypeFromProgID('InternetExplorer.Application');     object ie = Activator.CreateInstance(ieType);      //Navigate to the blank page in order to make sure the Document exists     //ie.Navigate2('about:blank');     Object[] parameters = new Object[1];     parameters[0] = @'about:blank';     ie.GetType().InvokeMember('Navigate2', BindingFlags.InvokeMethod | BindingFlags.IgnoreCase, null, ie, parameters);      //Get the Document object now that it exists     //Object document = ie.Document;     object document = ie.GetType().InvokeMember('Document', BindingFlags.GetProperty | BindingFlags.IgnoreCase, null, ie, null);      //document.Write(szSourceHTML);     parameters = new Object[1];     parameters[0] = szHtml;     document.GetType().InvokeMember('Write', BindingFlags.InvokeMethod | BindingFlags.IgnoreCase, null, document, parameters);      //document.Close()     document.GetType().InvokeMember('Close', BindingFlags.InvokeMethod | BindingFlags.IgnoreCase, null, document, null);      //ie.Visible = true;     parameters = new Object[1];     parameters[0] = true;     ie.GetType().InvokeMember('Visible', BindingFlags.SetProperty | BindingFlags.IgnoreCase, null, ie, parameters); } 

    The referenced SO question that originally said ‘not possible until C# 4.0’ was amended to show how it is possible in .NET 2.0.

    Does C# .NET support IDispatch late binding?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 75k
  • Answers 75k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer You can use as many event methods as you want,… May 11, 2026 at 2:39 pm
  • added an answer Refer to this question here: How to make my Windows… May 11, 2026 at 2:39 pm
  • added an answer Update: In the current version of F#, you can simply… May 11, 2026 at 2:38 pm

Related Questions

I have a website developed in ASP.Net 2.0 that is throwing the error Exception
Good morning. As the title indicates, I've got some questions about using python for
I am working on an SWT project as part of a team. We are
I am looking to purchase a new development PC. My budget is not more

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.