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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:04:22+00:00 2026-05-18T01:04:22+00:00

I have a legacy application written in C , and i would like to

  • 0

I have a legacy application written in C , and i would like to gradually move some code to c#. But before being able to rewrite everything i will need to have just few components writen in c# first that are going to be used from C.

  • 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-18T01:04:23+00:00Added an answer on May 18, 2026 at 1:04 am

    I assume your C# class is a static class. You need to create an interop layer in C++/CLI before you can use it in pure C. Create a C++/CLI class to wrap your C# class. Once that is done use the export function to export the specific C functions. C++/CLI will manage the interop on your behalf. The rule of thumb is if you class/function has any CLI it WILL BE CLI. So your extern functions should only return native datatypes.

    extern "C" __declspec( dllexport ) int MyFunc(long parm1);
    

    Here is an article to help you get started. It converts C++ to C# but the process is reversed in your case. CodeProject Unfortunately there is no convenient reverse PInvoke for pure C.

    Unfortunately I have never gone from C# to C. It sounds like an interesting project. Good luck!

    Ok If you have not figured it out yet i have a quick sample for you.

    C# CSLibrary.Math.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace CSLibrary
    {
        static public class Math
        {
            static public int Add(int a, int b)
            {
                int c = a + b;
                return c;
            }
        }
    }
    

    Cpp/C++ Project CPPCLibrary.h (Compiled with C++/CLI Option with project dependencies)

    #pragma once
    
    using namespace System;
    
    extern "C" __declspec( dllexport ) int MathAdd(int a, int b)
    {
        return CSLibrary::Math::Add(a, b);
    }
    

    C Project CTest.c (Compiled as C Code)

    #include "stdafx.h"
    #pragma comment(lib, "../Debug/CPPCLILibrary.lib") 
    
    extern __declspec( dllimport ) int MathAdd(int a, int b);
    
    int _tmain(int argc, _TCHAR* argv[])
    {
        int answer = MathAdd(10, 32);
        _tprintf(_T("%d\n"), answer);
        return 0;
    }
    

    All files are in the same solution but different projects. I have confirmed this has worked. I hope this helps anyone who comes across it.

    Cheers!

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

Sidebar

Related Questions

I would like to refactor a large legacy application originally written in Visual Basic
I have a rather legacy application EXE written in VB6 and running on a
I have to change some connection strings in an incredibly old legacy application, and
I currently have a database that gets updated from a legacy application. I'd like
I have a directory full of legacy code from a VB6 application. I have
I have a legacy application in our company built on... ahem; Classic VB (VB
I have a legacy VB6 application that was built using MSDE. As many client's
I have an old legacy application around for which I only have the installer.
I have a legacy C++ application that uses DDS for asynchronous communication/messaging. I need
I have a legacy C++-based application that timestamps incoming network traffic using the CRT

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.