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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:09:53+00:00 2026-05-26T09:09:53+00:00

I know one can use an index into an array to specify length of

  • 0

I know one can use an index into an array to specify length of the array for a marshaled C-array. However, I would like to do it a little different.

I would like the size to be a prefixed Int16. If I make it an entry of the array, I can’t control the marshaled size of the count specifier.

So, in short, how do I write a custom marshaller that prefixes an Int16 as a count.

Please note, I have to serialize the data, so no IntPtrs are allowed.

The part I’m stumped on, is how to implement GetNativeDataSize. I don’t have an IntPtr or Managed Object at that point, so how will I be able to marshal out the Int16 to get the count.

For example.

[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)]
class Something
{
    [MarshalAs(UnmanagedType.CustomMarshaler ... ]
    public ArrayItem[];
}

And the other class

[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)]
class ArrayItem
{
    public int Item;
}

In Native side, this would appear as

struct
{
    short count;
    int[] Item;
}

But since every variable length array on managed side would do this, I would like a custom marshaller to append the count for me.

Problems are

  • I don’t know what GetNativeDataSize should do, or how it will work, since I don’t have any reference to the native data.
  • I can’t rely on the LPArray, because the count must be an Int16
  • Will the array items marshal correctly, or does the array custom marshaller hide the items marshaller, or am I going to have to implement some generic marshaller (if that’s possible).
  • 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-26T09:09:53+00:00Added an answer on May 26, 2026 at 9:09 am

    I’m gonna say it…a custom marshaler feels like overkill. If you really want to do this with a custom marshaler, you’re going to have to use unsafe blocks/methods and pointer math to write the data.

    Why not have a class similar to your native struct, and wrap your array in that when marshaling? Really, you’re trying to pass a structure anyway; the only reason for the custom marshaler is to magically generate that struct from the array. Better to avoid the magic, IMO, and at the same time let the default marshaler do the grunt work.

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

Sidebar

Related Questions

I like to know how one can integrate the Qt libraries into an Enterprise
I would like to know which one is the best material that I can
Does any one know of a control that i can use with a ASP.Net
I know one can add event listener for window.error. However when working with Iframes,
I know that one can define an 'expected' exception in JUnit, doing: @Test(expect=MyException.class) public
Does any one know how can I convert a BSTR to an int in
Does any one know how can I cut the 1st 3 char in a
As you know, one can customize the width of the scrollbar width in Display
Does any one know from where can I download source code for Cassini. I
does any one know of any good countdown timer's for flash which i can

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.