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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:01:29+00:00 2026-05-31T13:01:29+00:00

I have a library whose functionality I want to eventually expose to .NET. The

  • 0

I have a library whose functionality I want to eventually expose to .NET. The method I want to expose has the following signature:

void DoSomething(std::list<SomeStruct>& someList);

The variable someList gets populated by DoSomething.

I know how to export from the library already. My main question is what would a “.NET friendly” interface look like for this function? I’d assume that std::list is a bad idea if I want to use C# with P/Invokes.

What other options are there? As the caller, I won’t know the size of the buffer that I should pass in ahead of time. Also, as the caller, I’d rather not make multiple calls to the function with small fixed-sized buffers nor would I want to pass in a super large buffer.

What’s the best practice for this case?

  • 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-31T13:01:33+00:00Added an answer on May 31, 2026 at 1:01 pm

    You can define a struct for use in the pinvoke call. Decorate it on native and mnaged sides, so that the packing is the same on each side. As for the variable sized out parameter, you could use ::GlobalAlloc to allocate an array that can then be deallocated in C#. Pass out an item count as well. In C#, the Marshal type has various methods to use to work with a GlobalAlloc’d array.

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

Sidebar

Related Questions

I have a function from a library whose signature says:- public void setColumnNames(N... columnNames);
We have written a large library functions whose prototypes mostly look like: void my_fun(
Of course most languages have library functions for this, but suppose I want to
I have a library consisting of approx 100 source files. I want one of
I have a library, and I want to migrate it from an old system
I have an experimental library whose performance I'm trying to measure. To do this,
so I have a library Mine.SuperFun which calls stuff in the library SuperFun whose
In a C++ library whose internals I'm rewriting I have some unsigned integer variables
I have a problem with a Library whose assembly is strongly typed and for
I have a double in Javascript whose value is, for example, 1.0883076389305e-311. I want

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.