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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:28:48+00:00 2026-05-20T06:28:48+00:00

I am working on an enterprise application development. the entire application is developed in

  • 0

I am working on an enterprise application development. the entire application is developed in c++, except the UI, which is developed in c#, now its time to hookup the UI with c++ code. After detailed study i choose PInvoke in order to do so.
All is successful, the only case where i stuck is that how can i pass collection to C++ code.
e.g:

C# Side Code

List<string> lst = new List<string>();
lst.Add("1");
lst.Add("2");
lst.Add("3");
lst.Add("4");

C++ Side Code

std::vector<std::string> vStr;

Now how do i pass lst to native C++ code

  • 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-20T06:28:49+00:00Added an answer on May 20, 2026 at 6:28 am

    As mzabsky mentioned, you cannot marshal these types. You can, however, marshal an array:

    The theoretical C++ export:

    extern "C" __declspec(dllexport) void __stdcall Foo(wchar_t const* const* values, int length)
    {
        // Check argument validity...
    
        // If you really need a vector
        std::vector<std::wstring> vStr(values, values + length);
    
        //...
    }

    The P/Invoke signature:

    [DllImport("foo.dll")]
    static extern void Foo([MarshalAs(UnmanagedType.LPArray, ArraySubType=UnmanagedType.LPWStr)] string[] values, int length);

    The call from C#:

    Foo(lst.ToArray(), lst.Count);

    Note that I’m using std::wstring here; you could instead use char instead of wchar_t, LPStr instead of LPWStr, and std::string instead of std::wstring.

    Note that this will allocate an array from the list and then the vector will copy the array’s contents. If the original list is small in size, this should be of negligible concern.

    Edit: fixing markup (&lt; and &gt;).

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

Sidebar

Related Questions

I am working on the architecture of a large enterprise application which will be
Suppose you're working on an enterprise project in which you have to get management
I'm working on an enterprise application that relies heavily on message queues, com+, databases,
I'm working with a multitier SOA based enterprise application with every complex business logics.
I recently started working at a company with an enormous enterprisey application. At my
Working with python interactively, it's sometimes necessary to display a result which is some
Is there anyone developing mobile industrial/enterprise/ERP/Inventory type applications who really loves their development tools
I am going to change my working sphere from Enterprise Web Applications written for
So I have an application I am working on at work that we have
I am working on a project which requires different validation sets for the same

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.