C# using C++ dlls and lib

  • Thread starter Thread starter tshad
  • Start date Start date
T

tshad

I have a program in C# that needs to access a couple of C++ dlls and libs.

Can this be done?

Thanks,

Tom
 
|I have a program in C# that needs to access a couple of C++ dlls and libs.
|
| Can this be done?
|
| Thanks,
|
| Tom
|
|

You can only call functions exported by DLL's, C# (and all other .NET
languages) cannot bind to libs.
Note also that with "exports" I mean C style exported functions. Search the
docs for PInvoke interop for more details.

Willy.
 
tshad said:
I have a program in C# that needs to access a couple of C++ dlls and libs.

Can this be done?

COM DLL's or Win32 DLL's.

COM stuff can be used directly.

Win32 DLL's can be used via dllimport.

A very simple example:

using System;
using System.Runtime.InteropServices;

class MainClass
{
[DllImport("msvcrt.dll")]
public static extern int system(string cmd);
public static void Main(string[] args)
{
Console.WriteLine("Hello world");
system("CLS");
}
}

Arne
 
Willy said:
Note also that with "exports" I mean C style exported functions. Search the
docs for PInvoke interop for more details.

Good point.

C++ mangled names is a problem.

Arne
 

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