A simple way involving the Foo class:
- Create a C ++ / CLI project, call this FooWrapper.
- Make FooWrapper depend on an unmanaged dll (as you usually did).
- Create a ManagedFoo managed class that contains one private instance field of type Foo *.
- provide general transfer functions in ManagedFoo, which are sent to the primary instance field.
- Optional (although recommended):
- convert parameters from .net idioms (strings, etc.) to C ++ idioms (std :: string or char *)
- catch unmanaged exceptions and throw managed ones instead
Then you make your C # code dependent on the FooWrapper / dll project and make sure that unmanaged ll is correctly deployed with it, how this is done depends on the unmanaged dll, but usually in the same directory.
If functions do not rely on instances of the class, then it is even simpler P / Invoke
ShuggyCoUk Feb 20 '09 at 13:53 2009-02-20 13:53
source share