0

We are planning to write C# wrapper for libssh2. I have following questions:

1) Since libssh2 is implemented in C/C++. How can I include a C++ dll in my C# project?

2) How can I get handle to the Session object of libssh2 in my C# project?

Thanks in advance for your help.

Jörgen Sigvardsson
  • 4,782
  • 2
  • 27
  • 50

1 Answers1

2

From C# you can call C-Method via p/Invoke and DLL-Import. So if you want to use a c++ library, you have to write a procedural c-wrapper. Here an example for dll-import:

 [DllImport("kernel32.dll")]
 public extern static void Sleep(uint msec);

That is how you hae to export the c functions:

_declspec(dllexport) void __cdecl Function1(void);

I would recommend that you read the following tutorial: Tutorial p/Invoke

The second solution is you write a C++/CLI wrapper, but this is much more complex: C++/CLI wrapper

Community
  • 1
  • 1
BendEg
  • 18,216
  • 14
  • 52
  • 120