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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:10:53+00:00 2026-05-28T05:10:53+00:00

My first question here :) I am working with an application written in C++

  • 0

My first question here 🙂

I am working with an application written in C++ (a map editor for a game) that has the front end UI written in C#. Since i’m new to C# i’m trying to do as much as possible on the C++ side.

From C# i want to call a C++ function that will return a list of structs with simple variable types (int and string) so that i can populate a listBox i have in the UI with them. Is this possible? How should i write the dll import function in C#?

I have tried searching here for the answer, but i only found post on how to pass lists from C# to C++.

The C++ code:

struct PropData
{
PropData( const std::string aName, const int aId )
{
    myName = aName;
    myID = aId;
}

std::string myName;
int myID;
};

extern "C" _declspec(dllexport) std::vector<PropData> _stdcall GetPropData()
{
std::vector<PropData> myProps;

myProps.push_back( PropData("Bush", 0) );
myProps.push_back( PropData("Tree", 1) );
myProps.push_back( PropData("Rock", 2) );
myProps.push_back( PropData("Shroom", 3) );

return myProps;
}

The C# import function:

    [DllImport("MapEditor.dll")]
    static extern ??? GetPropData();

EDIT:

After the post from Ed S. I changed the c++ code to
struct PropData
{
PropData( const std::string aName, const int aId )
{
myName = aName;
myID = aId;
}

    std::string myName;
    int myID;
};

extern "C" _declspec(dllexport) PropData* _stdcall GetPropData()
{
    std::vector<PropData> myProps;

    myProps.push_back( PropData("Bush", 0) );
    myProps.push_back( PropData("Tree", 1) );
    myProps.push_back( PropData("Rock", 2) );
    myProps.push_back( PropData("Shroom", 3) );

    return &myProps[0];
}

and the C# to
[DllImport(“MapEditor.dll”)]
static extern PropData GetPropData();

    struct PropData
    {
        string myName;
        int myID;
    }

    private void GetPropDataFromEditor()
    {
        List<PropData> myProps = GetPropData();
    }

but of course this doesn’t compile as GetPropData() doesn’t return anything that translates to a list.

Thanks a lot Ed S. for getting me this far!

  • 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-28T05:10:54+00:00Added an answer on May 28, 2026 at 5:10 am

    You’re not going to be able to marshall the std::vector into C# territory. What you should do instead is return an array. Sticking to basic types makes things a lot more simple when facing interop situations.

    std::vector guarantees that &v[0] points to the first element and that all elements are stored contiguously, so just pass the array back. If you’re stuck with the C++ interface as it is (which I don’t think you are) you will have to look into some more complex mechanism like COM.

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

Sidebar

Related Questions

I'm working on my first real WinForms application, and my boss has asked that
First question here so hello everyone. The requirement I'm working on is a small
Ok, I need help. This is my first question here. Background: I am working
first question here. I'm developing a program in C# (.NET 3.5) that displays files
First question here: it is a very short yet fundamental thing in Java that
this is my first question here :) I know that I should not check
Here's my first question at SO. I have a internal application for my company
We are working on a restful application that has a 'whiteboard' like feature. I
We're working on a freaky big service-oriented multilayered application, that has to be designed
It has been a long question, so here is the summary first, I have

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.