【发布时间】:2013-11-22 11:33:17
【问题描述】:
我有一个项目使用的库主要是基于 C++ 构建的。 带有这个库的交付的 DLL,我已经导入到我的 C# 项目中。 在 Unity 中导入以下方法后:
[DllImport("pst")]
private static extern int pst_get_sensor(PSTSensor sensor);
我需要这个 PSTSensor 结构,所以实际使用该方法。 在 C++ .h 文件中,结构定义为:
struct PSTSensor
{
char name[80]; /**< Device name */
int id; /**< Device identifier (for other tracking interfaces */
float pose[16]; /**< Device pose estimate as row-major matrix */
double timestamp; /**< Time the data was recorded */
};
我尝试在 C# 中复制它,结果如下:
struct PSTSensor{
PSTSensor(char[] name, int id, float[] pose, double timestamp){
this.name = name;
this.id = id;
this.pose = pose;
this.timestamp = timestamp;
}
public char[] name;
public int id;
public float[] pose;
public double timestamp;
}
在这个项目附带的示例 C++ 代码中,声明调用 pst_get_sensor(&sensor) 这个“&”符号,我不认识?我将如何在 C# 中调用此方法并使其工作?
我想我毁了这个结构,看看我以前从未和他们一起工作过。至少它不再在编译时抛出错误,但我认为它仍然是错误的。有什么想法吗?
提前非常感谢, 笑脸
【问题讨论】: