wireless_lab
wireless_lab

Reputation: 187

how to include cpp header files in a c# program

I am actually converting a cpp program into a c# dll. In cpp I have used some header files which contains some structs that are required. I am creating a dll in C#. How do I link the header files in C#? Can I build it as a static cpp library and link it to dll?

regards, shiksha

Upvotes: 0

Views: 1072

Answers (2)

ahmedsafan86
ahmedsafan86

Reputation: 1794

as @keugyeol said You can't include the C++ headers in a C# application, you can convert the c++ structures to C# ones, this site for the interoperability between C# and C++ look at their implementation of the structs, the following attribute is commonly used

[StructLayout(LayoutKind.Sequential)]

http://www.pinvoke.net/

but it is easier to convert the native c++ code to managed c++ and include your files, the output dll can be used in c#, or can be converted to C# using applications such ILSpy [that reverse the .Net Assembly in C# or VB Code]

Upvotes: 1

Keugyeol
Keugyeol

Reputation: 2435

You cannot directly use the C++ header file in C# but you can convert the C++ structs to C# quite easily, I suppose, since I am not aware of your specific struct types.

Upvotes: 1

Related Questions