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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:23:53+00:00 2026-05-23T02:23:53+00:00

I want to write an algorithmic library in standard, platform-independent C++. Can I then

  • 0

I want to write an algorithmic library in standard, platform-independent C++.

Can I then take the same C++ code and compile it for .NET so that a C# application can use the library?
If not, what is the easiest way to achieve this kind of interop?

  • 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-23T02:23:54+00:00Added an answer on May 23, 2026 at 2:23 am

    You have three ways to expose your library to easily be called from managed code:

    • write a C++/CLI wrapper for it that contains a public ref class – the C# code will call methods of this class, which will call native methods of your library
    • expose a C-style function from your library as a DLL – the C# code will use P/Invoke to call the function
    • write a COM component in C++ that uses your library and call it from the C# code by adding a COM reference to it.

    That third one, COM, I include only for completeness. It wouldn’t be my first choice. Or my third. It’s one thing if the COM component exists, it’s another to write it just for this.

    Between the first two it’s a matter of who else might use this library. If the C# code is the only one using it, do what you like. But for example you might have 15 or 20 native methods that set various properties, followed by a go or execute method that does the actual work. Because managed-native interop has a cost, I would tell you to write one C++/CLI function that takes 20 parameters, calls the various native functions and then calls the go or execute. This gives you a chunkier interface instead of chatty and reduces your interop costs.

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

Sidebar

Related Questions

I want to write an algorithm that can take parts of a picture and
I want to write some library code to be shared across products and across
I want write a little code analyzer which parses nested structures and translates into
I want to write a program in Prolog that confirms if a b-tree of
Guys, I am trying to write a class in C# that can be used
I want to write a generic averaging algorithm. That is, for any type T
I'm writing some code that uses a Tree (a regular tree that can have
I'm solving algorithmical problems, and i want to write custom functions and predicates that
I want to write a program that processes images. If there are good algorithm
I want to write a Java function that will get as input either int[]

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.