how to use a c++ dll from c# code

  • Thread starter Thread starter falk
  • Start date Start date
F

falk

i've a c++ dll and want to use the classes and methods
within from my c# code.
is this possible?
how can i do this?
do i have to recompile the c++ code with .NET compilers?

thanks a lot
falk
 
Hi falk,
You can use all C-style global functions exported by your c++ dll using
P/Invoke. You cannot use exported classes, thought. The only way to use
classes is to export them as COM objects.

HTH
B\rgds
100
 
falk said:
i've a c++ dll and want to use the classes and methods
within from my c# code.
is this possible?
how can i do this?
do i have to recompile the c++ code with .NET compilers?

Take a look at SWIG: www.swig.org
 
Arild,

All you have to do is add a reference to your dll. In your SolutionExplorer
window in VS.NET, right click on References, choose add reference, and click
browse to navigate to where your dll is stored. You should have a property
in your property window that allows you to "CopyLocal = true". And then use
your dll. Remeber that using C++ dlls in C# can be a little tricky as they
are not managed code.

Hope this helps,

Marco
 
Back
Top