tags:

views:

103

answers:

2
BYTE* pImageBuffer = NULL;
    eResult res = PlayerLib::CreateImageSnapshot( iPlayerRef, eBMP, &pImageBuffer );
   if( res > 0 )
     { 
         ....                                    // do something with the image
          WriteFile(FileHandle, pBuffer, eRes, NULL, NULL);
          ReleaseImageSnapshot( pImageBuffer );   // free the image buffer in not longer needed!
     }

here i can receive the image data in pImageBuffer and i could do the some image process

the same way I have tryed in c# like

 [DllImport("PlayerLib")]
   public static extern int CreateImageSnapshot(int iPlayerRef, eImageFormat imgFormat,byte[] ppImageBuffer);


byte[] bte ;
CreateImageSnapshot(iPlayerref,eImageFormat.ePNG,bte);

here its giving some unhandeld Exception..... hopefully the problem is in byte[] but i can't point out... please help me to overcome it.... thanks in advance

here it shoud return the imagedata in ppImageBuffer... but here it's giving zero byte only

A: 

One thing that looks off to me is your C# declaration of CreateImageSnapshot. Since your C++ code is correct, the third parameter must be a BYTE **. But in C# you have the third parameter as a byte[] which feels like an incompatible type.

R Samuel Klatchko
what kind of change made in my c# code to solve this one.
RV
A: 

My suggest to you would be to marshal BYTE ** as ref IntPtr. Your declaration would be:

[DllImport("PlayerLib")]  
public static extern int CreateImageSnapshot(int iPlayerRef,
                         eImageFormat imgFormat, ref IntPtr ppImageBuffer);

P.S. and sorry for my English, guys ;)

Tror
k tror how can i call this function byte[] bte ; CreateImageSnapshot(iPlayerref,eImageFormat.ePNG,ref bte); is't correct
RV
before you call this function you need to allocate some memory for buffer: int size = 10000;int[] array = new int[size];IntPtr buffer = Marshal.AllocCoTaskMem( Marshal.SizeOf(byte)* size);Marshal.Copy(array, 0, buffer, size);
Tror
The CreateImageSnapshot function apparently allocates the memory, you don't have to do it yourself. So just use the Marshal.Copy call and remember to free the buffer with ReleaseImageShapshot.
Mattias S