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

  • SEARCH
  • Home
  • 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 129439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:47:23+00:00 2026-05-11T05:47:23+00:00

The Question My question is: Does C# nativly support late-binding IDispatch? Pretend i’m trying

  • 0

The Question

My question is: Does C# nativly support late-binding IDispatch?


Pretend i’m trying to automate Office, while being compatible with whatever version the customer has installed.

In the .NET world if you developed with Office 2000 installed, every developer, and every customer, from now until the end of time, is required to have Office 2000.

In the world before .NET, we used COM to talk to Office applications.

For example:

1) Use the version independant ProgID

'Excel.Application' 

which resolves to:

clsid = {00024500-0000-0000-C000-000000000046} 

and then using COM, we ask for one of these classes to be instantiated into an object:

IUnknown unk; CoCreateInstance(     clsid,      null,     CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER,     IUnknown,      out unk); 

And now we’re off to the races – able to use Excel from inside my application. Of course, if really you want to use the object, you have to call have some way of calling methods.

We could get ahold of the various interface declarations, translated into our language. This technique is good because we get

  • early binding
  • code-insight
  • compile type syntax checking

and some example code might be:

Application xl = (IExcelApplication)unk; ExcelWorkbook workbook = xl.Workbooks.Add(template, lcid); Worksheet worksheet = workbook.ActiveSheet; 

But there is a downside of using interfaces: we have to get ahold of the various interface declarations, transated into our language. And we’re stuck using method-based invocations, having to specify all parameters, e.g.:

ExcelWorkbook workbook = xl.Workbooks.Add(template, lcid); xl.Worksheets.Add(before, after, count, type, lcid); 

This has proved, in the real world, to have such downsides that we would willingly give up:

  • early binding
  • code-insight
  • compile time syntax checking

and instead use IDispatch late binding:

Variant xl = (IDispatch)unk; Variant newWorksheet = xl.Worksheets.Add(); 

Because Excel automation was designed for VB Script, a lot of parameters can be ommitted, even when there is no overload without them.

Note: Don’t confuse my example of Excel with a reason of why i want to use IDispatch. Not every COM object is Excel. Some COM objects have no support other than through IDispatch.

  • 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-11T05:47:24+00:00Added an answer on May 11, 2026 at 5:47 am

    You can, relativly, use late-binding IDispatch binding in C#.

    http://support.microsoft.com/kb/302902

    Here’s some sample for using Excel. This way you don’t need to add a needless dependancy on Microsoft’s bloaty PIA:

    //Create XL Object xl = Activator.CreateInstance(Type.GetTypeFromProgID('Excel.Application'));  //Get the workbooks collection. //   books = xl.Workbooks; Object books = xl.GetType().InvokeMember( 'Workbooks',        BindingFlags.GetProperty, null, xl, null);  //Add a new workbook. //   book = books.Add(); Objet book = books.GetType().InvokeMember( 'Add',        BindingFlags.InvokeMethod, null, books, null );  //Get the worksheets collection. //   sheets = book.Worksheets; Object sheets = book.GetType().InvokeMember( 'Worksheets',       BindingFlags.GetProperty, null, book, null );  Object[] parameters;  //Get the first worksheet. //   sheet = sheets.Item[1] parameters = new Object[1]; parameters[0] = 1; Object sheet = sheets.GetType().InvokeMember( 'Item',        BindingFlags.GetProperty, null, sheets, parameters );  //Get a range object that contains cell A1. //   range = sheet.Range['A1]; parameters = new Object[2]; parameters[0] = 'A1'; parameters[1] = Missing.Value; Object range = sheet.GetType().InvokeMember( 'Range',       BindingFlags.GetProperty, null, sheet, parameters );  //Write 'Hello, World!' in cell A1. //   range.Value = 'Hello, World!'; parameters = new Object[1]; parameters[0] = 'Hello, World!'; objRange_Late.GetType().InvokeMember( 'Value', BindingFlags.SetProperty,        null, range, parameters );  //Return control of Excel to the user. //   xl.Visible = true; //   xl.UserControl = true; parameters = new Object[1]; parameters[0] = true; xl.GetType().InvokeMember( 'Visible', BindingFlags.SetProperty,       null, xl, Parameters ); xl.GetType().InvokeMember( 'UserControl', BindingFlags.SetProperty,       null, xl, Parameters ); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 124k
  • Answers 124k
  • 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
  • Editorial Team
    Editorial Team added an answer Are you running on OS 3.0? I saw the same… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer It looks like you need to register Apache::Session::Memcached with Apache::Session::Wrapper,… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer Use DATENAME or DATEPART: SELECT DATENAME(dw,GETDATE()) -- Friday SELECT DATEPART(dw,GETDATE())… May 12, 2026 at 1:19 am

Related Questions

The Question My question is: Does C# nativly support late-binding IDispatch? Pretend i'm trying
Recently I was talking with a friend of mine who had started a C++
The following snippet of C# code: int i = 1; string result = String.Format({0},{1},{2},
My question concerns c# and how to access Static members ... Well I don't
I've been reading up on RAII and single vs. two-phase construction/initialization. For whatever reason,

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.