I’ve general questions while importing a C++ created DLL into C#.
1) I’ve written C++ functions making use of pointers such as double pointers, array of pointers etc.
e.g. static int someFunc(char *var[])
How do i re-use them as C# does not support pointers.
2) Do I need to expose all the functions through [DllImport()] in C#? i.e. I’ve a function called someFunc which calls other functions internally. Should I expose those functions too under ‘DllImport’
3) Can anyone please explain why I require to handle the unmanaged code in C# especially when I import dlls from C++?
Point 1 Answer:
use the unsafe keyword in function declaration in C#
point 2 Answer:
There is no need to import all functions. only import someFunc()
point 3 answer:
C# uses managed code which is type safe and refers to some valid memory location. However pointers as in C++ may or may not refer to any valid memory location. So you need to handle unmanaged code in C#.