I have a c program that I want to reprogram in c#.
In the C program, a function is used which accesses an address of a 2d array.
Dll.h
int Fg_AddMem(Fg_Struct * Fg, void *pBuffer, const size_t Size, const frameindex_t bufferIndex, dma_mem *memHandle);
Programm.cpp:
#include "Dll.h"
.
.
#define BUFFERS 4
#define BUFFERSIZE(1024*1024)
static char buf[BUFFERS+1][BUFFERSIZE]
for (int i=0; i<BUFFERS; i++)
{
int ret = Fg_AddMem(fg, buf[i], BUFFERSIZE, i, mhead);
.
.
}
Now i want to programm it in C#
First, i created a class to import the Dll function over the pInvoker addon
CAM_SISO.cs:
[DllImport ("fglib5.dll", setLastError = true, CallingConvention = CallingConvention.Cdecl)]
public extern static int Fg_AddMem(IntPtr Fg, IntPtr pBuffer, int size, int bufferIndex, IntPtr memHandle);
I'm also created a BackgroundWorker for the for-loop
Application.cs:
int BufCnt=4;
int Buffersize = 1024*1024;
BackgroundWorker worker_current_add_mem;
.
this.Load += new EventHandler(this.add_mem_backgroundworker);
.
private void add_mem_backgroundworker(object sender, EventArgs e)
{
.
.
worker_current_add_mem.DoWork += new DoWorkEventHandler(worker_Add_mem);
}
.
private void worker_Add_mem(object sender, DoWorkEventArgs e)
{
char[,]buf = new char[BufCnt+1,Buffersize];
for(int i=0; i<BufCnt; i++)
{
int ret = CAM.SISO.Fg_AddMem(Fg, ??? , Buffersize, i, mHead);
.
.
}
}
So now my question is, how can I pass the address of the 2d array to an IntPtr. Also I would like in c, that the array is incremented in the first field to add a memory.
How do I proceed??
I already tried it with GCHandle and Marshal.Copy but nothing works for me.