1

I need to use a program made in C for a C# project , and for this I need to generate a DLL in Visual Studio 2013, anyone have any tutorial or know how to do it? I want make a DLL for a structs and read/write functions in C, cheers guys.

Mohit S
  • 13,723
  • 6
  • 34
  • 69
  • 2
    possible duplicate of [Access a method from a DLL from C# program](http://stackoverflow.com/questions/6392372/access-a-method-from-a-dll-from-c-sharp-program) – user2864740 Sep 17 '15 at 07:06

2 Answers2

1

You have to use p/invokes. I think this is very often discussed here. Take a look at: Access a method from a DLL from C# program

Community
  • 1
  • 1
BendEg
  • 20,098
  • 17
  • 57
  • 131
0

DLL is probably overkill for what you are doing. You can just write a C procedure and P/Invoke it using CDecl. The problem is that you need to know a whole lot for this. If you are simply trying to iterate over an array fast for a performance critical section, you are better off using structs in C#, slapping unsafe on your method, and then using pointers and addresses to do what you want to do. Code that looks a whole lot like C/C++ is perfectly legal in C#.

See a reference here: MSDN : Unsafe Pointers

Also fished out a somewhat dated reference showing how to P/Invoke the visual c Runtime printf function as an example. Keep in mind that things get really hard when you need to give a pointer to a function and when you need to read offsets etc. to pass around structs. You'll need to pin anything you pass into the method to stop it from being moved by the garbage collector, which will also have performance implications.

MSDN: CDecl P/Invoke example

Spence
  • 28,526
  • 15
  • 68
  • 103