- I was wondering if I can use a library –written in C++– in C#
- The problem is that library has its own structures and classes..
Will I be able to use it in C#?
Thanks
EDIT
This library is open source..
so if my requirements needs something special in C++ code, I will be able do it…
You cannot directly use C++ classes in managed code. The chief problems are not being able to use the same memory allocator as used by the C++ code and not being able to invoke the constructor and destructor easily. A Microsoft employee posted a blog post to show that it is not impossible. I would not recommend doing this.
COM is a solution but that invariably requires a fairly big rewrite and good COM programming skillz. A managed class wrapper in the C++/CLI language is usually the best solution. You could take a peek at the SWIG tool to consider auto-generating those wrapper classes. Beware however that this tool can easily create more problems than it solves.