Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 绑定到Monotouch中的第三方库-映射uint8_t*和uint8_t**_C#_C_Binding_Xamarin.ios - Fatal编程技术网

C# 绑定到Monotouch中的第三方库-映射uint8_t*和uint8_t**

C# 绑定到Monotouch中的第三方库-映射uint8_t*和uint8_t**,c#,c,binding,xamarin.ios,C#,C,Binding,Xamarin.ios,我正在尝试使用monotouch绑定到第三方条形码扫描库-到目前为止,除了库头文件中定义的以下方法外,所有方法都运行良好: /** * Main scan function. Invokes all activated decoders by priority. * For successful scan, allocates pp_data buffer and pass it to user. * User should deallocate *pp_data pointer when

我正在尝试使用monotouch绑定到第三方条形码扫描库-到目前为止,除了库头文件中定义的以下方法外,所有方法都运行良好:

/**
 * Main scan function. Invokes all activated decoders by priority.
 * For successful scan, allocates pp_data buffer and pass it to user.
 * User should deallocate *pp_data pointer when no more needed.
 *
 * @param[in]   pp_image                Byte array representing grayscale value of image pixels.
 *                                      Array shold be stored in row after row fashion, starting with top row.
 * @param[in]   lenX                    X axis size (width) of image.
 * @param[in]   lenY                    Y axis size (length) of image.
 * @param[out]  pp_data                 On successful decode, library allocates new byte array where it stores decoded
 *                                      string result. Pointer to string is passed here. User application is responsible
 *                                      for deallocating this buffer after use.
 *
 * @retval      >0                      Result string length for successful decode
 * @retval      MWB_RT_BAD_PARAM        Null pointer or out of range parameters
 * @retval      MWB_RT_NOT_SUPPORTED    Unsupported decoder found in execution list - library error
 */
extern int MWB_scanGrayscaleImage(uint8_t *  pp_image,  int lenX,  int lenY, uint8_t **pp_data);
我已经有一段时间没有直接处理C数据结构了,我不清楚如何映射
uint8_t*pp_图像
uint8_t**pp_数据

第一个参数处理来自像素缓冲区的灰度图像。我正在从
CMSampleBuffer
获取一个图像缓冲区。它需要亮度转换的字节数组、字节数组的内存地址,还是将以
IntPtr
的形式传入
pixelBuffer.GetBaseAddress(0)

最后一个参数在初始化为
unsigned char*pResult=NULL的指针中传递在objective-C演示中,然后在找到有效扫描时填充数据。同样,我不知道如何初始化和传入,因为不能在C#中传入未初始化/空字节数组

我的绑定库代码目前如下(尽管我也尝试过使用
IntPtr
,通过ref传递,以及在不安全模式下传递直接地址):


对于迄今为止我所尝试的一切,结果值一直在-1中返回,它映射到“scan failed”。如果有任何帮助,我们将不胜感激。

第一个参数是保存亮度值的字节数组的内存地址,但是将数组作为参数传递应该做到这一点

最后一个参数必须引用将存储对输出字符串的引用的(有效)内存位置

你有没有试过下面的方法

[DllImport ("__Internal")]
extern static int MWB_scanGrayscaleImage (byte[] pp_image, int lenX, int lenY, out byte[] pp_data);
public static int ScanGrayscaleImage (byte[] pp_image, int lenX, int lenY, out byte[] pp_data)
{
    int result;

    fixed (byte** pp_data_ptr = &pp_data) {
        result = MWB_scanGrayscaleImage(pp_image, lenX, lenY, pp_data_ptr);
    }

    return result;
}

我建议将uint8\u t**绑定为IntPtr,因为库将无法分配托管字节[]

也许是这样的:

[DllImport ("__Internal")]
extern static int MWB_scanGrayscaleImage (byte[] pp_image, int lenX, int lenY, out IntPtr pp_data);
public static int ScanGrayscaleImage (byte[] image, int lenX, int lenY, out byte[] data)
{
    IntPtr pp_data;

    int result = MWB_scanGrayscaleImage (image, lenX, lenY, out pp_data);
    if (result > 0) {
        data = new byte[result];
        Marshal.Copy (pp_data, data, 0, result);
        Marshal.FreeHGlobal (pp_data); // I think this is what you want...
    } else {
        data = null;
    }

    return result;
}

感谢您的帮助,我觉得我至少在大概的范围内,但我在这一行遇到了一个错误:
fixed(byte**pp_data\u ptr=&pp_data){
无法获取的地址、大小或声明指向托管类型“byte[]”的指针
[DllImport ("__Internal")]
extern static int MWB_scanGrayscaleImage (byte[] pp_image, int lenX, int lenY, out IntPtr pp_data);
public static int ScanGrayscaleImage (byte[] image, int lenX, int lenY, out byte[] data)
{
    IntPtr pp_data;

    int result = MWB_scanGrayscaleImage (image, lenX, lenY, out pp_data);
    if (result > 0) {
        data = new byte[result];
        Marshal.Copy (pp_data, data, 0, result);
        Marshal.FreeHGlobal (pp_data); // I think this is what you want...
    } else {
        data = null;
    }

    return result;
}