Jump to content

how to compile C function inside C-Sharp program?

- - - - -

  • Please log in to reply
3 replies to this topic

#1
serendipity1276

serendipity1276

    Newbie

  • Members
  • Pip
  • 2 posts
Hi,

I do not know how to code in C-Sharp. I want to add a C function to an existing, working C-Sharp program, and compile it. Let's say the C function is something like this:

Test_Function ( )

{

/* C codes go here. */

}

What do I need to do to make this C-Sharp program compile with the above test C function added? I tried adding standard C libraries at the top of the C-Sharp program, but it won't compile.

#include "stdio.h"
#include "stdlib.h"
#include "string.h"


Please help. Thank you.

#2
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
What your wanting to do is write and run C code in a C# IDE? As far as I know that just plain won't work. You can convert the C code into C# code then add it, but just plain using C code won't work. Post your C code and we can help convert possibly.

EDIT: You may perhaps be able to put the C code in a file and use C# to call a program to compile it.
~ Committed.
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.

#3
Chris

Chris

    Newbie

  • Members
  • Pip
  • 5 posts
I think it would be easier to just recode it into c#. If you know C then the transistion should be easy, depending on the contents of the actual function that is. Could you import the C code into a UML editor and then use the editor to export into C# code? I've never tried, but it may be possible.

#4
TradeM

TradeM

    Newbie

  • Members
  • Pip
  • 3 posts
If you want to keep you code in C then you will have to keep it in a separate DLL. And call the DLL function by C# using PInvoke
----------------------
U Zafar
SE
Retail POS Software - TradeMeters™ is a Reliable Point of Sale Software Solution POS software

Edited by TradeM, 29 November 2011 - 12:51 AM.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users