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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:08:08+00:00 2026-05-14T18:08:08+00:00

I am developing game editor in C# that uses c++ lib files. I want

  • 0

I am developing game editor in C# that uses c++ lib files.
I want RTTI for C++ classes in C#.
Is it possible to get RTTI of C++ class in C#?
If yes how?

  • 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-14T18:08:08+00:00Added an answer on May 14, 2026 at 6:08 pm

    You can not expose native C++ types or code directly to the .NET platform.

    There are however three ways of interacting with “native” C & C++ code from .NET (in C#, VB.Net or whatever).

    1. COM
    2. P/Invoke
    3. CLI/C++

    COM is probably the easiest to use from the .NET side. Just add the COM object to your .NET project as a reference and start interacting with the interfaces and classes. For more detail on interactive with COM in .NET have a read of a book like this:

    .NET and COM: The Complete Interoperability Guide

    http://www.amazon.com/NET-COM-Complete-Interoperability-Guide/dp/067232170X

    This of course requires you to expose your game engine objects as COM objects. This is non-trivial.

    The next easiest to use is P/Invoke. If your game code is packaged in a standard windows DLL with a C calling convention you can access functions in that DLL using P/Invoke. For example:

    public static class UserDll
    {
        [DllImport("user32.dll")]
        private static extern bool FlashWindow(IntPtr hwnd, bool bInvert);
    
        public static void FlashWindow(System.Windows.Forms.Form window)
        {
            FlashWindow(window.Handle, false);
        }
    }
    

    You can do a lot with P/Invoke. Even have your C/C++ code call back into C# with delegates and what not.

    I’ve built game engine tools in the past that used P/Invoke to call out to functions exposed in a DLL. You just have to be careful about the management of native resources. Here the IDisposable interface and class finalizers become your friends. Eg:

    public class Player : IDisposable
    {
        private IntPtr _thePlayer;
    
        public Player()
        {
            _thePlayer = CreatePlayer();
        }
    
        ~Player()
        {
            Dispose(false);
        }
    
        public void Dispose()
        {
            Dispose(true);
        }
    
        private void Dispose(bool disposing)
        {
            if (disposing)
            {
               // dispose of managed objects (ie, not native resources only)
            }
    
            if (_thePlayer != IntPtr.Empty)
            {
                DestroyPlayer(_thePlayer);
                _thePlayer = IntPtr.Empty;
            }
        }
    
        [DllImport("gameengine.dll")]
        private static extern IntPtr CreatePlayer();
    
        [DllImport("gameengine.dll")]
        private static extern void DestroyPlayer(IntPtr player);
    }
    

    There is a downside to using P/Invoke. First it can add a significant marshalling overhead to native calls (though there are ways of speeding that up). It also requires a C API in the gameengine.dll. If your engine is C++ classes you have to provide a C API to the C++ classes. This can add a whole lot of work (or require a code generator).

    I’m not going to go into any more detail on all the messy details of dealing with Marshalling managed objects/data to and from native code. Just know that it can be done and that MSDN is your friend here.

    The third and probably best way of exposing native C++ code to .NET is via CLI/C++ mixed mode assemblies. CLI/C++ lets you mix native and managed code together in a single assembly fairly seamlessly.

    CLI/C++ has a funny syntax but if you’re a C++ programmer it is not hard to adapt. An example might be something like this:

    using namespace System;
    
    // CLI/C++ "managed" interface 
    interface class IDog
    {
        void Bark();
    };
    
    #pragma managed(push off)
    
    // Native C++
    class Pet
    {
    public:
       Pet() {}
       ~Pet() {}
    
       const char* GetNativeTypeName()
       {
           return typeid(Pet).name();
       }
    };
    
    #pragma managed(pop)
    
    // CLI/C++ "managed" class
    ref class Dog : IDog
    {
    private:
        Pet* _nativePet;
    
    public:
        Dog()
          : _nativePet(new Pet())
        {}
        ~Dog()
        {
            delete _nativePet; 
            _nativePet = 0;
        }
    
        void Bark()
        {
            // Managed code talking to native code, cats & dogs living together, oh my!
            Console::WriteLine("Bow wow wow!");
    
            Console::WriteLine(new System::String(_nativePet->GetNativeTypeName()));
        }
    };
    
    void _tmain()
    {
        Dog^ d = gcnew Dog();
        d->Bark();
    }
    

    My recommendation (having done exactly what you’re trying to do) is that for anything more than moderately complex, the best solution is to try and provide a CLI/C++ API to your game engine. I learnt everything I needed to know about CLI/C++ off MSDN but I hear this book is good if you like meaty tomes.

    Expert Visual C++/CLI: .NET for Visual C++ Programmers

    http://www.amazon.com/Expert-Visual-CLI-Programmers-Experts/dp/1590597567

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

Sidebar

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.