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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:15:32+00:00 2026-05-18T12:15:32+00:00

I want to export a C++ class, which has a member std::vector<int> . How

  • 0

I want to export a C++ class, which has a member std::vector<int>. How to export this class so that my C# application can consume it? And how to write the corresponding .Net code?

This is what I tried so far, following the examples given here.

 #include <vector>
#  define BOOSTGRAPH_API __declspec(dllexport)
# define EXPIMP_TEMPLATE

EXPIMP_TEMPLATE template class BOOSTGRAPH_API std::vector<int>;

     class BOOSTGRAPH_API MyClass
    {
    public:
        std::vector<int> VectorOfInts;

    public:
        bool operator < (const MyClass  c) const
        {
            return VectorOfInts < c. VectorOfInts;
        }
        bool operator == (const MyClass  c) const
        {
            return VectorOfInts == c. VectorOfInts;
        }
    };

But then I’m stucked.

  • 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-18T12:15:32+00:00Added an answer on May 18, 2026 at 12:15 pm

    What are you trying to do? I see BOOST_GRAPH_API, what are you up to? You will not be able to use native C++ code from .Net directly, neither you should! That would force you to compile all imported dependencies on C++ standard library and boost(!) with clr support…

    You need to define interfaces to your classes along with proper factory methods. These can be safely exported and wrapped by C++/CLI objects which you can directly reference within .Net programs:

    // imyclass.h
    
    __declspec( dllexport ) 
    IMyClass* CreateInstance();
    
    __declspec( dllexport ) 
    class IMyClass {
    public:
        virtual int CompareTo(IMyClass*) = 0;
        virtual ~IMyClass() {}
    };
    
    // myclass.h
    
    #include "imyclass.h"
    #include <vector>
    
    class MyClass : public IMyClass {
        std::vector<int> mIntVector;
    public:
        virtual int CompareTo(IMyClass*);
        // constructors and access functions go here...
    };
    
    // myclass.cpp
    
    #include "myclass.h"
    #include <memory>
    
    IMyClass* CreateInstance() {
     return new MyClass;
    }
    
    // implementations of whatever MyClass should do go here...
    

    Observe that only the interface IMyClass and its creator is exported by the dll, nothing else. In a C++/CLI project, you define a C++/CLI disposable wrapper which holds a pointer to IMyClass and imports only imyclass.h. The wrapper which imprt only IMyClass and it’s creator should be similar to something shown below, but take care to get the finalizer semantics right, not sure at the moment what is generated autmatically by the compiler…:

    ref class IMyClassWrapper {
        IMyClass* mPtrResource;
    
     public:
    
        int CompareTo(IMyClassWrapper^ pOther) {
            return this->mPtrResource->CompareTo(pOther->mPtrResource);
        }
    
        IMyClassWrapper() {
         mPtrResource = ::CreateInstance();
        }
    
        ~IMyClassWrapper() {
         this->!IMyClassWrapper();
        }
    
     protected:
    
        !IMyClassWrapper() {
         delete mPtrResource;
         mPtrResource = 0;
        }
    
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MEF based solution that has several exported implementations of an interface.
Perhaps a stupid question: I have a List of type <Data> which I want
My application is using MEF to export some classes from an external assembly. These
I've got a circular dependency that recently came about because of a change in
i really dont get it work. say i have some classes with the same
I would like to make a single Android app for multiple Android versions (possibly
once in a while you have to draw a picture of your (planned) IT
I have a MEF's CompositionContainer, a contract (say IFoo) and a module (Prism module
I am new to eclipse + Java. I am trying to create executable jar
I try to load a simple DLL compiled with GCC in cygwin into a

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.