I would like to add my C++ application a C# .NET GUI .
My C++ application is very simple but I have a some Pointer and Reference .
What is the Best way C# will recognize this pointer and Reference?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There are several ways, here are some, and it depends on your taste and on your project.
a) Use COM interop, if your C++ project is written in COM.
b) Use COM interop, you can write COM wrappers to your C++ application and use it from C#.
c) Use C++/CLI, that is, convert your project to become a Managed C++ application and create managed classes in C++ that use your C++ code.
You can also write a managed C++ dll that loads your C++ dll or static library.
d) Use P INVOKE C calls, exports DLL C functions from your C++ code that work with your C++ class, call the C functions from C# using [dllimport] attribute.
You can use type IntPtr and the better and safer SafeHandle to express pointers and references.
All ways have good things and drawbacks, but every listed tehcnique need a “middle layer”, you cannot call C++ code directly from C#.