外部函数中参数的正确格式 - c#

我正在创建一个使用RiVLIB库(http://riegl.com/index.php?id=224)读取rxp数据的c#应用程序。我不知道如何正确定义外部函数的属性。

我已经可以调用一些函数,例如scanifc_get_library_version和scanifc_point3dstream_open,但是我无法找出scanifc_point3dstream_read函数的参数正确格式。

调用scanifc_point3dstream_read(从scanifc_point3dstream_open获取h3ds)后,我得到System.AccessViolationException。

呼叫看起来像:

IntPtr h3ds = IntPtr.Zero;
int sync_to_pps = 0;
//this works ok -> h3ds gets assigned
int opened = scanifc_point3dstream_open_with_logging("190910_092831.rxp", ref sync_to_pps, "log.txt", ref h3ds);

uint PointCount = 0;
int EndOfFrame = 1;
const uint BLOCK_SIZE = 10;
scanifc_xyz32[] BufferXYZ = new scanifc_xyz32[BLOCK_SIZE];
scanifc_attributes[] BufferMISC = new scanifc_attributes[BLOCK_SIZE];
ulong[] BufferTIME = new ulong[BLOCK_SIZE];
//throws AccessViolationException
int read = scanifc_point3dstream_read(
    h3ds, BLOCK_SIZE,
    ref BufferXYZ, ref BufferMISC, ref BufferTIME,
    ref PointCount, ref EndOfFrame);
[DllImport("scanifc-mt.dll")]
static extern int scanifc_point3dstream_read(
    IntPtr h3ds,
    uint want,
    [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] ref scanifc_xyz32[] pxyz32,
    [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] ref scanifc_attributes[] pattributes,
    [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] ref ulong[] ptime,
    ref uint got,
    ref int end_of_frame);

使用的结构:

[StructLayout(LayoutKind.Sequential)]
struct scanifc_xyz32
{
    float x;
    float y;
    float z;
}

[StructLayout(LayoutKind.Sequential)]
struct scanifc_attributes
{
    float amplitude;
    float reflectance;
    ushort deviation;
    ushort flags;
    float background_radiation;
}

这是库函数标头:

SCANIFC_API int
scanifc_point3dstream_read(point3dstream_handle, scanifc_uint32_t,
 scanifc_xyz32 *, scanifc_attributes *,
 scanifc_time_ns *, scanifc_uint32_t *,
 scanifc_bool *);

和typedefs:

typedef IMPLEMENTATION_DEFINED scanifc_uint8_t; // unsigned 8 bit integer
typedef IMPLEMENTATION_DEFINED scanifc_int8_t; // signed 8 bit integer
typedef IMPLEMENTATION_DEFINED scanifc_uint16_t; // unsigned 16 bit integer
typedef IMPLEMENTATION_DEFINED scanifc_int16_t; // signed 16 bit integer
typedef IMPLEMENTATION_DEFINED scanifc_uint32_t; // unsigned 32 bit integer
typedef IMPLEMENTATION_DEFINED scanifc_int32_t; // signed 32 bit integer
typedef IMPLEMENTATION_DEFINED scanifc_uint64_t; // unsigned 64 bit integer
typedef IMPLEMENTATION_DEFINED scanifc_int64_t; // signed 64 bit integer
typedef IMPLEMENTATION_DEFINED scanifc_uintmax_t; // unsigned largest available bitsize integer
typedef IMPLEMENTATION_DEFINED scanifc_intmax_t; // signed largest available bitsize integer
typedef IMPLEMENTATION_DEFINED scanifc_float32_t; // 32 bit floating point
typedef IMPLEMENTATION_DEFINED scanifc_float64_t; // 64 bit floating point
typedef char* scanifc_sz;
typedef const char* scanifc_csz; // pointer to zero delimited string
typedef scanifc_int32_t scanifc_bool; // pointer to constant zero delimited string 

typedef struct scanifc_xyz32_t scanifc_xyz32; // a point in cartesian coordinates
typedef struct scanifc_attributes_t scanifc_attributes; // per point attributes
typedef scanifc_uint64_t scanifc_time_ns;
struct scanifc_xyz32_t {
 // public data members
 scanifc_float32_t x; // x coordinates
 scanifc_float32_t y; // y coordinates
 scanifc_float32_t z; // z coordinates
};

struct scanifc_attributes_t {
 // public data members
 scanifc_float32_t amplitude; // relative amplitude in [dB]
 scanifc_float32_t reflectance; // relative reflectance in [dB]
 scanifc_uint16_t deviation; // a measure of pulse shape distortion.
 scanifc_uint16_t flags; // some bit-mapped attribute values
 scanifc_float32_t background_radiation; // background radiation.
};

c#参考方案

所以几个小时后,我找到了解决方案...如果有人认为有帮助,我将其发布。我在这篇文章中找到了答案:
Referencing an object array in C# PInvoke

int read = scanifc_point3dstream_read(
    h3ds, BLOCK_SIZE,
    BufferXYZ, BufferMISC, BufferTIME,
    ref PointCount, ref EndOfFrame);
[DllImport("scanifc-mt.dll")]
static extern int scanifc_point3dstream_read(
    IntPtr h3ds,
    uint want,
    [Out] scanifc_xyz32[] pxyz32,
    [Out] scanifc_attributes[] pattributes,
    [Out] ulong[] ptime,
    ref uint got,
    ref int end_of_frame);

LeetCode题解计算机为什么是基于二进制的?

可以是三进制么?二进制有什么好处?题解:为什么叫电子计算机?算盘应该没有二进制

LeetCode题解统计城市的所有灯泡

这个是我刚毕业的时候,一个真实的面试题,这是一个开放题。题目描述:想办法,将一个城市的所有灯泡数量统计出来。题解:费米估算法1、如果某个城市常驻人口有1000万2、假设每5人居住在一套房里,每套房有灯泡5只,那么住宅灯泡共有1000万只3、假设公众场所每10人共享一只灯泡,那么共有100万只4、主要的这两者相加就得出了1100万只当然实际上这是估算的,具体应…

LeetCode题解黑白圆盘

一个圆盘被涂上了黑白二色,两种颜色各占一个半圆。圆盘以一个未知的速度、按一个未知的方向旋转。你有一种特殊的相机可以让你即时观察到圆上的一个点的颜色。你需要多少个相机才能确定圆盘旋转的方向?题解:可以用一个相机即可

LeetCode题解圆上任取三点构成锐角三角形的概率

来自字节跳动的一道几何题题解:1/4

LeetCode题解深度优先遍历和回溯的关系?

深度优先遍历的范围更大还是回溯的范围更大?为什么?题解:我的理解是:dfs是回溯思想的一种体现- 回溯:是在整个搜索空间中搜索出可行解,在搜索过程中不断剪枝回退,这是回溯的思想,这个搜索空间并没有限制于特定的数据结构。- dfs:dfs是指特定的数据结构中如图,树(特殊的图)中搜索答案,范围限制在了特定的数据结构。个人拙见。