0

I'm trying to compile a program written in C++ (SuitSparse, does sparse matrix calculations). I need to compile it to be used by a csharp.net application. What's the best way to do this?

1) Compile it and reference it like any other c++ dll? 2) is there any program that can convert this to clr (or something .net would understand better) 3) ??

5
  • might be helpful: stackoverflow.com/questions/935664/… Commented Aug 2, 2012 at 19:41
  • possible duplicate of Using C++ Class DLL in C# Application Commented Aug 2, 2012 at 19:46
  • .net supports c++. (at least the tooltip for the .net tag on SO mentions it). Commented Aug 2, 2012 at 19:52
  • well, my questions is more about what's he best way to use the source code...i don't necessarily have to create a c++ dll Commented Aug 2, 2012 at 20:26
  • I wouldn't make a C++ DLL, I would statically link the C++ code into your C++/CLI project. Commented Aug 2, 2012 at 22:13

1 Answer 1

1

You can't use C++ DLLs in C# programs, but you can use C++/CLI DLLs in C# programs. Create a C++/CLI wrapper for the C++ project and build it into a DLL.

The alternative is to use COM interfaces, as Ed S. pointed out, but I think that doesn't provide a very C#-ish library feel. It really depends on what you feel most comfortable with, I would assume C# dlls.

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

7 Comments

Incorrect. You can reference native DLL's directly from a C# project if it exposes COM interfaces.
is creating the c++ dll and wrapper using the source the only way to use it from .net? (hopefully this is not too dumb of a question)
@EdS. COM seems like it's not the most natural way to interact with a library, I feel like a DLL would be much more natural for a C# developer.
@ColinD yes, what about P/Invoke?
|

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.