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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:12:29+00:00 2026-05-23T00:12:29+00:00

I have a COM component written in C++. One of the MIDL interfaces has

  • 0

I have a COM component written in C++. One of the MIDL interfaces has a function defined like:

HRESULT __stdcall GetValues(
    int length,
    [ref, size_is(*length)] VARIANT_BOOL out[]);

GetValues just populates the out array with values:

for (int i = 0; i < length; ++i)
    out[i] = (i % 2) != 0;

I’ve tried to call it from C# using the following:

private bool[] mValues = new bool[100];
...
myComObject.GetValues(100, ref this.mValues[0]);

I’m getting access violation errors. I think the C++ is interpreting the bools as 2-byte values, whereas in C# they’re only allocated as 1-byte values.

I’ve looked at Default Marshaling for Boolean Types but I’m not sure how to apply that to my situation. The MarshalAs attribute doesn’t seem to change anything. I’m not sure how to use it for passing an array by reference?

[MarshalAs(UnmanagedType.U1)]
private bool[] mValues = new bool[100];
  • 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-23T00:12:30+00:00Added an answer on May 23, 2026 at 12:12 am

    VARIANT_BOOL is indeed a 2-byte value: http://blogs.msdn.com/b/oldnewthing/archive/2004/12/22/329884.aspx

    So when you marshal it as UnmanagedType.VariantBool, you’re not changing anything because you’re marshalling it in as exactly the same thing that’s being returned anyway.

    What I would try first is UnmanagedType.U1. If that doesn’t work, I would try to a short[] instead of bool[].

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

Sidebar

Related Questions

I have a COM component written in C++ that has a Print function. This
I have a COM component written in C# that makes calls to ConfigurationManager.AppSettings.Get(...). This
I have written a COM component in unmanaged C++ to provide customers access to
I have an old C++ COM component which has to stay in Visual Studio
I have a 32 bit COM component DLL and this DLL is written in
I have written a com component in .NET and if I try to take
I have a Windows Service written in .NET C# which calls a COM component.
I have a COM component written in VB6 that I'm using from a Visual
I have a COM SDK written in C++ and I'd like to create documentation
I have written a custom component for jsf. The renderer extends com.sun.faces.renderkit.html_basic.ListboxRenderer. My component

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.