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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:01:00+00:00 2026-05-11T19:01:00+00:00

I have a C++ class I’d like to access from a C# application. I’ll

  • 0

I have a C++ class I’d like to access from a C# application. I’ll need to access the constructor and a single member function. Currently the app accepts data in the form of stl::vectors but I can do some conversion if that’s not likely to work?

I’ve found a few articles online which describe how to call C++ DLLs and some others which describe how to make .dll projects for other purposes. I’m struggling to find a guide to creating them in Visual Studio 2008 for use in a C# app though (there seem to be a few for VS 6.0 but the majority of the options they specify don’t seem to appear in the 2008 version).

If anyone has a step-by-step guide or a fairly basic example to get going from, I’d be very grateful.

  • 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-11T19:01:00+00:00Added an answer on May 11, 2026 at 7:01 pm

    The easiest way to interoperate between C++ and C# is by using managed C++, or C++/CLI as it is called. In VisualStudio, create a new C++ project of type “CLR Class Library”. There is some new syntax for the parts that you want to make available to C#, but you can use regular C++ as usual.

    In this example, I’m using std::vector<int> just to show that you can use standard types – however, in an actual application, I’d prefer to use the .NET types where possible (in this case a System::Collections::Generic::List<int>).

    #pragma unmanaged
    #include <vector>
    #pragma managed
    
    public ref class CppClass
    {
    public:
       CppClass() : vectorOfInts_(new std::vector<int>)
       {}
    
       // This is a finalizer, run when GC collects the managed object
       !CppClass()
       { delete vectorOfInts_; }
    
       void Add(int n)
       { vectorOfInts_->push_back(n); }
    
    private:
        std::vector<int>* vectorOfInts_;
    };
    

    EDIT: Changed the class to hold the vector by pointer instead of by value.

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

Sidebar

Ask A Question

Stats

  • Questions 142k
  • Answers 142k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer No, you can't dealloc UIViewControllers that are not visible. What… May 12, 2026 at 8:16 am
  • Editorial Team
    Editorial Team added an answer This was just compilation issue. I had to use boost… May 12, 2026 at 8:16 am
  • Editorial Team
    Editorial Team added an answer Figured it out. Basically the center div is lowered because… May 12, 2026 at 8:16 am

Related Questions

I have a C++ class I'd like to access from a C# application. I'll
I have a C++ class and I am trying to run it in Ubuntu:
I have a C++ class MyObject and I want to be able to feed
I have written a C++ class that I need to share an instance of
I have a class ( EAGLView ) which calls a member function of a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.