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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:50:08+00:00 2026-05-15T19:50:08+00:00

I have a legacy code implemented in C (not C++). I would like to

  • 0

I have a legacy code implemented in C (not C++). I would like to be able to call a few methods in this C code from my C# code (on Windows). What would be the best approach to interface between the two language? Please note that the method in C is not stateless. We need to call two methods:

  1. initialization() => this will initialize the data structure and load data from files into memory. This method will be called once.
  2. ComputeSomething(parameters) => there will be several calls from C# to this method.

Note: These two methods actually call several other methods but these are only the two methods that we would like to expose to C# (the code is quite complicated, that’s why we do not want to port to C#)

I have been able to import the c code into visual studio and able to compile the code successfully. I know that we can probably implement the C code as windows service but I am looking for a solution that allow us to call C method from C# directly. Any pointers is highly appreciated! (is COM interop related to what I am looking to do?)

  • 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-15T19:50:09+00:00Added an answer on May 15, 2026 at 7:50 pm

    Sounds like you can use P/Invoke for this. Check out this site for tips:

    http://www.pinvoke.net/

    Also, try searching SO for advice on P/Invoke and Google for

    c# pinvoke calling c code

    I don’t have any technical examples at hand, but I have written some .NET code which called Win32 API’s via P/Invoke. The tricky part is getting the method signatures correct when passing parameters. This might help you out there.

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

Sidebar

Related Questions

I have some legacy code that looks like this: void* getData(DataType dataType) { switch(dataType)
We have legacy C++ code performing high-performance data processing (e.g., large volumes of data
I inherited some legacy Java (1.4) code and this design decision appears regularly. I
I have legacy code that I'm trying to obsolete that I cannot change. Its
I have legacy code with properties defined as : private string name; public string
I have some legacy code to reuse written in c++ with opengl but most
A legacy database has a column changed (containing an updated_at timestamp). This results in
I'm working on a legacy project that has heavy use of Singletons. While most
I know a little bit about Object Oriented design , but I'm not sure
This question is probably language-agnostic, but I'll focus on the specified languages. While working

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.