0

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

2 Answers 2

1

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]

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.