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 128595
In Process

The Archive Base Latest Questions

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

The class mshtml.HTMLDocumentClass in Microsoft.mshtml.dll assembly has a method: public virtual void write(params object[]

  • 0

The class mshtml.HTMLDocumentClass in Microsoft.mshtml.dll assembly has a method:

public virtual void write(params object[] psarray); 

Avoiding the real question for a moment, what code would you use to call write()? Would you use:

String html = '<html><body>Hello, world!</body></html>'; mshtml.HTMLDocumentClass doc; ... doc.write(html); 

or would you use:

String html = '<html><body>Hello, world!</body></html>'; mshtml.HTMLDocumentClass doc; ... object[] params = new Object[1]; params[0] = html; doc.write(params); 

Because both of those throw an exception. (Type mismatch. 0x80020005)

The HTMLDocumentClass.write method actually comes from IHTMLDocument2 interface, which is documented as:

IHTMLDocument2::write Method

Writes one or more HTML expressions to a document in the specified window.

Syntax

HRESULT write(    SAFEARRAY *psarray ); 

Parameters

psarray

   [in] A **BSTR** that specifies the text and HTML tags to write. 

So in reality the write method needs a pointer to a SAFEARRAY, even though Microsoft’s Microsoft.mshtml interop assembly define the write method as taking a regular array:

public virtual void write(params object[] psarray); 

Ignoring the mshtml interop declaration, i have to construct a SAFEARRAY object (verses an object array), fill it with a BSTR string (verses a String), and stuff it into a parameter that must be an object array.


Note: i’m unsure of the meaning of the params keyword. It is used to indicate a variable number of parameters.

Does that mean that it can take multiple array parameters?

object[] array1 = new Object[1]; array1 [0] = alpha; object[] array2 = new Object[1]; array2 [0] = bravo; object[] array3 = new Object[1]; array3 [0] = charlie; object[] array4 = new Object[1]; array4 [0] = delta;  doc.write(array1, array2, array3, array4); 

Or is object[] the method in which multiple parameters are passed, and you must literally create an array?

object[] params = new Object[4]; params[0] = alpha; params[1] = bravo; params[2] = charlie; params[3] = delta; doc.write(params); 

Or is the array[] just a decoy, and really you pass:

doc.write(alpha, bravo, charlie, delta); 

When i originally used this code, from a native Win32 app, the BSTR was placed inside a SAFEARRAY. In IDispatch based automation, everything is inside an array. In this case the late binding code:

doc.write(html); 

was converted by the compiler into a SAFEARRAY, where the zero-th element contains a BSTR string (which is a length prefixed unicode string).

My problem becomes one of trying to construct a SAFEARRAY, converting a String into a BSTR, placing the BSTR into the zero-th element of the SAFEARRAY, and passing a variable that contains a SAFEARRAY to one that only accepts an object array (object[]).

This is the real question: how to create a BSTR SAFEARRAY?


Microsoft.mshtml

C:\Program Files\Microsoft.NET\Primary Interop Assemblies\Microsoft.mshtml.dll

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

    The declaration for the write method on the IHTMLDocument2 interface created by TLBIMP/VS.NET is incorrect. It should be:

    void Write([In, MarshalAs(UnmanagedType.SafeArray)] object[] psarray); 

    You will have to define this interface in code and then use that.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer All those files require higher permissions to access than normal,… May 12, 2026 at 2:55 pm
  • Editorial Team
    Editorial Team added an answer Check out the FormsAuthenticationTicket on MSDN FormsAuthenticationTicket ticket = new… May 12, 2026 at 2:55 pm
  • Editorial Team
    Editorial Team added an answer It's not just enums. Enums are just special kinds of… May 12, 2026 at 2:55 pm

Related Questions

I found a code of winform here: http://www.wincustomize.com/articles.aspx?aid=136426&c=1 And it works fine as a
I need to rewrite the domain names on web pages served by a DLL
Please help me I am New in PHP and since last 5 Hours i
The class method to create an index path with one or more nodes is:

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.