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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:01:36+00:00 2026-05-13T15:01:36+00:00

I have a class implemented in C++ that’s responsible for the arithmetic computation of

  • 0

I have a class implemented in C++ that’s responsible for the arithmetic computation of the program, and an interface using WPF. I process the input with C# but then how can I use my C++ class?

I’ve seen some comments about making a managed C++ wrapper class to interact with it, but I don’t know where to start. Nor do I know how I’d go to compile it along with all the other code. I can’t really find a tutorial on this, and the stuff google shows on managed C++ doesn’t really seem helpful.

Anything out there to help me out? This doesn’t seem unreasonable to me.

EDIT Tried m3rLinEz solution but it’s giving me a BadImageFormatException, I think it’s because the DLL isn’t generated. I did everything as told, I don’t know what happened. Any ideas?

  • 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-13T15:01:36+00:00Added an answer on May 13, 2026 at 3:01 pm

    Have you take a look at C++/CLI?

    Let me give a very short example. Here is the source file from a Visual C++ -> CLR -> Class Library project. It basically get Windows username and return it.

    Please note that, in order to get this compiled, you have to go into project settings and mark "Additional Dependencies" as "Inherit from parent" because we are using those Windows libs (kernel32.lib, user32.lib, ..)

    // CSCPP.h
    
    #pragma once
    
    #include "windows.h"
    
    using namespace System;
    
    namespace CSCPP {
    
        public ref class Class1
        {
            // TODO: Add your methods for this class here.
        public:
            String^ GetText(){
                WCHAR acUserName[100];
                DWORD nUserName = sizeof(acUserName);
                if (GetUserName(acUserName, &nUserName)) {
                    String^ name = gcnew String(acUserName);
                    return String::Format("Hello {0} !", name);
                }else{
                    return gcnew String("Error!");
                }
            }
        };
    }
    

    Now created a new C# project and add reference to our first C++/CLI Class Library project. And then call the instance method.

    namespace CSTester
    {
        class Program
        {
            static void Main(string[] args)
            {
                CSCPP.Class1 instance = new CSCPP.Class1();
                Console.WriteLine(instance.GetText());
            }
        }
    }
    

    This gave the following result on my machine:

    Hello m3rlinez !

    C++/CLI is basically a managed extension over C++ standard. It allows you to utilize CLR classes and data types in your C++/CLI project and also expose this to managed language. You can created a managed wrapper for your old C++ library using this. There are some weird syntaxes such as String^ to define reference type to CLR String. I find "Quick C++/CLI – Learn C++/CLI in less than 10 minutes" to be useful here.

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

Sidebar

Related Questions

If I have a class that needs to implement an interface but one or
Let's say I have a class that implements the IDisposable interface. Something like this:
I'm currently writing a class that implements the SeekableIterator interface and have run into
I have the simple class using auto-implemented properies: Public Class foo { public foo()
I have a service class implemented in Java 6 / Spring 3 that needs
I have class A, with methods foo and bar, that are implemented by A1
I have a class that implements multiple interfaces. I would like to register these
I have a custom class that implements that IComparable. This class is stored in
I have a custom class that implements ICollection , and this class is readonly,
I have a generic class that I'm trying to implement implicit type casting for.

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.