Search code examples
c#.netdll

compiling C code and C# code both into .NET DLL


I have a C# .NET DLL (call it CS_Code.dll) which is using

[DllImport("C_Code.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]

C_Code.dll contains mainly C code in extern "C" clauses.

When I will be using this assembly (CS_Code.dll) later in a project. I want to save from having to deliver two DLLs. All should be in one DLL.

Would it be possible to include (compile) the C-code into the .NET (e.g. as a library) making one .NET DLL out of it?


Solution

  • You can create a mixed-mode assembly which contains both native and managed code, however it's quite a topic so I suggest you read the section about it here on MSDN:

    Mixed (Native and Managed) Assemblies