C# 有人能找到等价的c代码吗

C# 有人能找到等价的c代码吗,c#,pinvoke,C#,Pinvoke,这是C++代码> CreateImageSnapshot,(int,eIMAEGRATH,字节**)< /C> >在VC++中实现 字节** PlayerLib::CreateImageSnapshot (iPlayerRef,static_cast<eImageFormat>(lFormat), &pBuffer); 在这里,我需要外接CreateImageSnapshot函数,我想知道如何传递参数 提前感谢正如我在上一个问题中建议的那样,定义为: [D

这是C++代码> CreateImageSnapshot,(int,eIMAEGRATH,字节**)< /C> >在VC++中实现
字节**

PlayerLib::CreateImageSnapshot (iPlayerRef,static_cast<eImageFormat>(lFormat),
        &pBuffer);
在这里,我需要外接CreateImageSnapshot函数,我想知道如何传递参数


提前感谢

正如我在上一个问题中建议的那样,定义为:


[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);
}


但非托管函数不返回缓冲区的大小。您需要在func中再添加一个参数或以res.返回数组长度。

k Tror如何调用此函数CreateImageSnapshot(1,imgFormat.jpeg,?);如何传递必须传递的字节数组参数:IntPtr buffer=new IntPtr();好吧,它返回了一些位置。。如何更改指向字节[]数组的指针要将IntPtr转换为字节[],您需要将其从非托管内存复制到托管内存。字节[]arrayRes=新整数[size];封送处理副本(imgBuffer,arrayRes,0,大小);。但是您还需要从这个函数中获得缓冲区的大小。没有它,就无法复制yur arrayintpttr buffer=new IntPtr();int[]arrayRes=新的int[size];封送处理副本(缓冲区,数组,0,大小);这不是正确的代码

[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);
}