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

  • Home
  • SEARCH
  • 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 3677650
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:14:50+00:00 2026-05-19T03:14:50+00:00

I have a C++ console Exe which does some progamming. Now i wanted to

  • 0

I have a C++ console Exe which does some progamming. Now i wanted to write a C# GUI which does some of the programming that the C++ exe does. I was thinking of few approaches,

  1. Write the C# GUI with all programming in C++ done from scratch.(I do not want to do this for the amount of rework it entails)
  2. Build a C++ dll which does the programming and have it imported in GUI app.(Now here i have a concern. How do i capture the output of the routines in c++ dll and display it in GUI? Should i return the output as string for every routine that the app calls.? Since i dont know managed c++ iam going to build an unmanaged C++ dll. )
  • 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-19T03:14:51+00:00Added an answer on May 19, 2026 at 3:14 am

    Building a C++/CLI dll really isn’t that hard. You basically use unmanaged C++ code except that you define a “public ref class” which hosts the functions you want the C# code to see.

    What kind of data are you returning? Single numbers, matrices of numbers, complex objects?

    UPDATE: Since it has been clarified that the “output” is iostreams, here is a project demonstrating redirection of cout to a .NET application calling the library. Redirecting clog or cerr would just require a handful of additional lines in DllMain patterned after the existing redirect.

    The zip file includes VS2010 project files, but the source code should also work in 2005 or 2008.

    The iostreams capture functionality is contained in the following code:

    // compile this part without /clr
    class capturebuf : public std::stringbuf
    {
    protected:
        virtual int sync()
        {
            // ensure NUL termination
            overflow(0);
            // send to .NET trace listeners
            loghelper(pbase());
            // clear buffer
            str(std::string());
            return __super::sync();
        }
    };
    
    BOOL WINAPI DllMain(_In_ HANDLE _HDllHandle, _In_ DWORD _Reason, _In_opt_ LPVOID _Reserved)
    {
        static std::streambuf* origbuf;
        static capturebuf* altbuf;
        switch (_Reason)
        {
        case DLL_PROCESS_ATTACH:
            origbuf = std::cout.rdbuf();
            std::cout.rdbuf(altbuf = new capturebuf());
            break;
        case DLL_PROCESS_DETACH:
            std::cout.rdbuf(origbuf);
            delete altbuf;
            break;
        }
    
        return TRUE;
    }
    
    // compile this helper function with /clr
    void loghelper(char* msg) { Trace::Write(gcnew System::String(msg)); }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a console application that require to use some code that need administrator
I have a console application project in C# 2.0 that needs to write something
I have a console application. A class (let's say Worker) does some work in
I have a console app that needs to display the state of items, but
I have a console program written in C# that I am using to send
I have a console application that will be kicked off with a scheduler. If
I have a console application that I would like to run as 'NT AUTHORITY\NetworkService',
I have a console application written in Delphi. I saw that I can have
Scenario I have a windows service written in C# that performs some processing based
I have an App.config file in my project that gets copied to NameOfExe.exe.config at

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.