Now from this C++ function if i want to pass the array or array values (received) to C# class library, is there a way to do that.
First you need to give a callback to your C++ code, then you need to convert the unmanaged data to managed data. You can do something like that:
C++ code:
typedef void (__stdcall *YOUR_CALLBACK)(char** files, int count);
extern "C" __declspec(dllexport) void __stdcall SetCallback(YOUR_CALLBACK callback)
{
char* files[] = { "first string", "second string" };
callback(files, 2);
}
C# code:
delegate void YOUR_CALLBACK(IntPtr files, int count);
[DllImport("Native.dll", CallingConvention = CallingConvention.StdCall)]
static extern void SetCallback(YOUR_CALLBACK callback);
static void CalledFromC(IntPtr files, int count)
{
IntPtr[] stringPointers = new IntPtr[count];
Marshal.Copy(files, stringPointers, 0, count);
string[] strings = new string[count];
for (int i = 0; i < count; i++)
strings[i] = Marshal.PtrToStringAnsi(stringPointers[i]);
...
}
[STAThread]
static void Main()
{
SetCallback(CalledFromC);
}