Thursday, July 9, 2009

How do you call C code from C# in the same executable?

The C code is to be linked in to the same executable as the C# code. Perhaps it should be a separate Assembly? Or a DLL? If in a separate DLL, how do I call it from C#?

How do you call C code from C# in the same executable?
I would do a separate compile, and do a shell-call from C#,


just like calling up a batch file or separate executable.


I'm not a C# person (used to do lots of C, though) but it works when I'm doing VB.
Reply:Make a separate .dll from the C code. In your C# project, add a reference to that C .dll (right-click the project and choose "Add Reference..." then click the "Browse" tab and find your C .dll file. Once you have a reference, you can create an instance of the object in the .dll (or call it's function directly if it's static).


No comments:

Post a Comment