Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use C code in a C# Project? Wrapper class?

I have a C code and I want to use this in C#.

Is there a possibillity except rewriting this code?


1 Answers

Build the C code as a DLL, and then use "P/Invoke" to call it. You'll need to learn a bit about interop, which is an area I don't know very much about, I'm afraid – but here are a few links:

  • A rather old article, but it looks fairly good
  • BCL Team Blog talking about the P/Invoke Interop Assistant
  • A recent MSDN Magazine article
  • The MSDN interop guide
like image 89
Jon Skeet Avatar answered Apr 26 '26 22:04

Jon Skeet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!