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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:14:37+00:00 2026-06-16T20:14:37+00:00

I’m using a native DLL. I’m not sure, but I think I can’t use

  • 0

I’m using a native DLL. I’m not sure, but I think I can’t use PInvoke decl’s with it since it does not export any functions and does not have a manifest. The DLL is delivered with a header file, explaining how to use it. The header file defines countless structs, enums and one class to be constructed using a factory method which is accessed via a Windows function ::GetProcAddress (security through obscurity).
This class holds functions I would like to use in managed code.

I have successfully wrapped the class in a CLI ref class and can call trivial methods on it, wrapping those as well.

I’m going through the process of converting some structs from the header file to managed structs. For example, Native structs:

struct FooACL{
    int               action;                
    unsigned long     from,to;               
    char              comment[64]; 
    int               reserved[17];          
};

Turns into managed struct:

[StructLayout(LayoutKind::Sequential, CharSet = CharSet::Ansi)]
public value struct ManagedFooACL{
     int   action;                
     int   from,to;     
     [MarshalAs(UnmanagedType::ByValTStr, SizeConst = 64)]
     String^    comment;
     [MarshalAs(UnmanagedType::ByValArray, SizeConst = 17)]
     array<int>^ reserved;
};

As far as I can tell this should make the managed struct blittable? And any other struct that follows a similar pattern or levels of nested structure. As long as a layout is specified and none blittable are adorned with MarshalAs, will the structure as a whole be blittable?

And so, I’m attempting to see if there is a way to use Marshal::Copy or Marshal::PtrToStructure to convert an FooACL* array to array<ManagedFooACL>^.

I get the FooACL* array from a function call; I do not allocate it myself.

int total;
FooACL* foos = unamagedClass->GetFooACLS(&total);

total is an in/out that gets the size of the array returned.

What I managed to do so far, and what work is:

ManagedFooACL first = static_cast<ManagedFooACL>(Marshal::PtrToStructure(IntPtr(&foos [0]), ManagedFooACL::typeid));

What I can’t wrap my mind around is why this does not:

array<ManagedFooACL>^ mfoos = gcnew array<ManagedFooACL>(total);
Marshal::PtrToStructure(IntPtr(&foos), mfoos);

This throws a:

System.ArgumentException was unhandled
  Message=The specified structure must be blittable or have layout information.
Parameter name: structure
  Source=mscorlib
  ParamName=structure

Is there a way to copy array data in one call or do I really need to do a for loop? It seems kind of silly with all this marshaling capability.

  • 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-06-16T20:14:38+00:00Added an answer on June 16, 2026 at 8:14 pm

    Having done some more research it looks like the answer is no. It is not possible to auto marshal an array of structs without looping.

    I think the main reason struct marshaling works with PtrToStructure is because the structure is static/predefined. The compiler knows how to lay out the memory. Since, you get a dynamic size array there’s no way to specify the memory lay out ahead of time. So you must loop dynamic number of structs.

    Alternatively, if you knew that you will always be getting an array of X length, you could define your own managed struct holding one element, namely the array of ManagedFooACL with a ByValArray and SizeConst value of X, and just cast the native array to the struct.

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

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Does anyone know how can I replace this 2 symbol below from the string
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
I am using JSon response to parse title,date content and thumbnail images and place
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I am confused How to use looping for Json response Array in another Array.
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only

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.