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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:00:47+00:00 2026-05-14T02:00:47+00:00

I am working on a solution, most of its core engine is developed as

  • 0

I am working on a solution, most of its core engine is developed as Win32 C++ (and is Platform independent and is also used on OS X), some time ago we needed to call C++ dll’s of core engine from C# and I was able to Load main solution’s DLL in C# (by the help of some threads here on SO). but now we have certain things implemented in Managed C# dll and need to use it in Win32 C++ project? (and just function definitions and dll are provided)

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

    You can create a managed C++ interop DLL to act as a wrapper around the C# library.

    Most tutorials on managed C++ unfortunately only explain how to wrap unmanaged C++ for use in C#. But it can work the other way also.

    Define an abstract interface class in your native C++ code, then create a concrete subclass inside the managed C++ DLL. Call into your C# objects in the method implementations.

    Finally, export a factory function that will instantiate the implementation class and return a base-class pointer that your native code can use.

    Here’s a quick example:

    First, define the class interface in your native DLL.

    interopclassbase.h

    class InteropClassBase
    {
    public:
        virtual void doStuff() = 0;
        virtual int getValue() = 0;
        virtual void getString(CString* outStr) = 0;
    };
    

    Now you need to create a C++/CLI DLL that will allow you to mix native and managed code in a single assembly. Add a new C++ project to your solution, and in the project configuration set the “Common Language Runtime Support” option to Mixed (/clr).

    Once you’ve added a reference to your C# library (which we’ll call ManagedLibrary) we can implement the interop class:

    interopclass.cpp

    #include "interopclassbase.h"
    #include <vcclr.h>
    
    public class InteropClass : public InteropClassBase
    {
    protected:
        gcroot<ManagedLibrary::ManagedObject^> m_managedObject;
    
    public:
        InteropClass()
        {
            m_managedObject = gcnew ManagedLibrary::ManagedObject();
        }
    
        virtual void doStuff()
        {
            m_managedObject->doStuff();
        }
    
        virtual int getValue()
        {
            return m_managedObject->getValue();
        }
    
        virtual void getString(CString* pOutStr)
        {
            System::String^ managedString = m_managedObject->getString();
            CString nativeString(managedString); // overloaded CString constructor
            if (pOutStr) *pOutStr = nativeString;
        }
    };
    
    __declspec(dllexport) InteropClassBase* getImplementationPointer()
    {
       return new InteropClass();
    }
    

    Now you just need to load the interop DLL from your native project and call the exported function.

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

Sidebar

Related Questions

No related questions found

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.