tags:

views:

103

answers:

2

This is c++ code CreateImageSnapshot, (int, eImageFormat, BYTE**) in VC++ we implementing BYTE**

PlayerLib::CreateImageSnapshot (iPlayerRef,static_cast<eImageFormat>(lFormat),
        &pBuffer);

here i need to import the dll and do the same process in c#.. Can anyone find equivalent C# code like

[DllImport("PlayerLib", SetLastError = false, 
                   EntryPoint = "CreateImageSnapshot")]
public static extern int CreateImageSnapshot(...);

Here I need to extern the CreateImageSnapshot function and I want to know how to pass the argument

thanks in advance

A: 

i guess that BYTE** in c# is byte[][]

Omu
[DllImport("PlayerLib", SetLastError = false, EntryPoint = "CreateImageSnapshot")] public static extern int CreateImageSnapshot(1,"jpeg",byte[][] pBuffer); is't correct
RV
just try it, and you will see
Omu
it's not working Omu. do u have any other idea
RV
+1  A: 

As I suggested in you previous question the definition will be:


[DllImport("PlayerLib", SetLastError = false, EntryPoint = "CreateImageSnapshot")]
public static extern int CreateImageSnapshot(int player, eImageFormat imgFormat,
                                             ref IntPtr imgBuffer);


byte[] img;
IntPtr imgBuff = new IntPtr();

int res = CreateImageSnapshot(1, eImageFormat.jpeg, ref imgBuff);
int size = ????
if (res > 0)
{
  img = new byte[size];
  Marshal.Copy(imgBuff, img, 0, size);
}

but you unmanaged function does not returns the size of buffer. you need to add one more parameter to your func or return array lenth in res.

Tror
k Tror how can i call this function CreateImageSnapshot(1,imgFormat.jpeg, ? ); how to pass the byte array argument
RV
you have to pass: IntPtr buffer = new IntPtr();
Tror
k fine it's returns some location.. how can change that pointer to byte[] array
RV
to convert IntPtr to byte[] you need to copy it from unmanaged memory to managed. byte[] arrayRes = new int[size]; Marshal.Copy(imgBuffer, arrayRes, 0, size);. But you also need to get from this function the size of buffer. Without it you can't copy yur array
Tror
IntPtr buffer = new IntPtr(); int[] arrayRes = new int[size]; Marshal.Copy(buffer, arrayRes, 0, size);is't correct code
RV
ok, I'll edit my answer to explain
Tror
ok my need is i need to send byte[] to that function and it ll return the some image bytes . simpily i have to save that image in my local path
RV
thanks tror i got output... thanks lot
RV
you cant pass simply byte[] because your unmanaged function needs reference to byte array. The only one solution is to pass IntPtr and then copy from it to your managed array. But as I said your function must return the size of unmanaged array.
Tror
yes Tror... are u from India.. you can say if u wish
RV
not. I'm from Russia :)
Tror
hi tror i have lot of problem in my module... i need your help man... if you can means give your mail id .
RV
ok, equilibrity [at] ya [dot] ru
Tror