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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:47:21+00:00 2026-05-27T00:47:21+00:00

I am working with a third-party COM component (i.e. do not have its code).

  • 0

I am working with a third-party COM component (i.e. do not have its code). The method in question has the following outline:

HRESULT GetTableInfo(  
[in] BSTR bstrTableName, 
[in,out] SAFEARRAY(BSTR) bstrColumnTitles, 
[in,out] SAFEARRAY(long) lColumnPos );

I have tried to pass a ref to a fixed-size array ((Array)string[6]) and to a List.ToArray(), but it keeps crashing on me. E.g.

Array arr1 = (Array) new string[500];
Array arr2 = (Array) new int[500];
table.GetTableInfo(filename, ref arr1, ref arr2);

To be more specific: I already tried any value for the size (the correct one should be 44). Tried the same for the capacity of a List<>, but that didn’t help either. I also tried different types, but it does not accept any other than int.

I don’t know why it keeps crashing on me with a general error of that COM component (basically indicating that something is wrong, yet not saying what exactly), since I can confirm that the following VB code works:

Dim TitleList() As String
Dim PositionList() As Long 
Call objTable.GetTableInfo(txTableFile.Text, TitleList, PositionList)

Does anyone have a clue on why this happens? Or alternatively, can anyone provide me a port of that VB code to C#? I have tried to google for tutorials, but all they say is “only fixed size arrays are allowed”. I wonder how that code works then, as no size is specified.

Thx i.a.

  • 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. Editorial Team
    Editorial Team
    2026-05-27T00:47:22+00:00Added an answer on May 27, 2026 at 12:47 am

    Have you read Default Marshaling for Arrays? As far as I can tell this should “just work” as long as you use the MarshalAs attribute on the PInvoke declaration to indicate that the array should be marshalled as a safe array.

    As far as I can tell the correct PInvoke declaration should be something along the lines

    public static string extern GetTableInfo(
        string tableName,
        [MarshalAs(UnmanagedType.SafeArray, SafeArraySubType=VT_BSTR)]
        ref string[] columnTitles,
        [MarshalAs(UnmanagedType.SafeArray, SafeArraySubType=VT_I8)]
        ref long[] columnPos
    );
    

    Can you show us what your PInvoke declaration looks like?

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

Sidebar

Related Questions

I'm working with third-party COM object that has some of its methods passing values
I'm currently working on a wrapper for a third party component (not the best
I have a working custom login realm (provided by a third-party) for Glassfish 3.1.1.
I am working with a third-party framework, and the code is pretty bad, and
I am working with a third party plugin, that has a small bug. This
I'm working in an application where a third-party has exposed two services one is
I'm working with a third-party product. It uses JavaScript (non-JQuery) code on the page
I have an application I'm working on that uses two third party libraries, each
I am having problems with working with a third party XML string that contains
I'm working in a project which needs to clean up some third party XSD

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.