How to use .dll created with C++ in C#?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have a dll created earlier by VC++ which export a class. And now i want to
use this class in C# code, how can i do it?

And what if it is a static library(.lib)?

Thanks in advance

Joe Cai
 
CAIBird said:
I have a dll created earlier by VC++ which export a class. And now i want to
use this class in C# code, how can i do it?
And what if it is a static library(.lib)?

By far the easiest is to open up your DLL project again, turn on "CLI"
in Projects>Settings>General, and turn your class into a "ref class"
rather than just a "class", and rebuild. This way it will produce a
normal .net assembly with classes that can be used by any other .net
language.
 
THX.
But I have no source code :)

Lucian Wischik said:
By far the easiest is to open up your DLL project again, turn on "CLI"
in Projects>Settings>General, and turn your class into a "ref class"
rather than just a "class", and rebuild. This way it will produce a
normal .net assembly with classes that can be used by any other .net
language.
 
CAIBird said:
Hi,

I have a dll created earlier by VC++ which export a class. And now i want to
use this class in C# code, how can i do it?
You can't, you can only call exported functions with "C" linkage. What you can do is write a
managed wrapper class using C++/CLI (VS2005). Search MSDN for "C++ Interop" for details.
And what if it is a static library(.lib)?
You can't use a .lib from C#.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top