c#与c++间传递数组的问题 (SWIG)

巴拉莱卡 2008-05-10 04:36:59
通过swig作中转的
我看使用手册上介绍如果传数组的话要先转成 lvalue,
用typedef 定义了了一个数组。
typedef double vec2d[2];

/***************************
33.8.5 Lvalues
When generating wrapper code, it is necessary to emit datatypes that can be used on the left-hand side of an assignment operator
(an lvalue). However, not all C datatypes can be used in this way---especially arrays and const-qualified types. To generate a
type that can be used as an lvalue, use the following function:
SwigType *SwigType_ltype(SwigType *ty)
Converts type ty to a type that can be used as an lvalue in assignment. The resulting type is stripped of qualifiers and arrays
are converted to a pointers.
The creation of lvalues is fully aware of typedef and other aspects of the type system. Therefore, the creation of an lvalue may
result in unexpected results. Here are a few examples:
typedef double Matrix4[4][4];
Matrix4 x; // type = 'Matrix4', ltype='p.a(4).double'
***************************/


但是不知道为什么,转出来都是SWIGTYPE_P*.cs的类,无法使用的。
但是typedef struct/double 都可以。

在.i文件里面都补完还是不行, 有谁能够提供一个成功的例子么?
...全文
652 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
BIGBIRDINWOODS 2008-06-02
  • 打赏
  • 举报
回复
不熟,但,傳數組要這么復雜?
巴拉莱卡 2008-05-12
  • 打赏
  • 举报
回复

/ * this was automatically generated by swig */

using System;
using System.Runtime.InteropServices;

public class SWIGTYPE_p_a_3__float {
private HandleRef swigCPtr;

internal SWIGTYPE_p_a_3__float(IntPtr cPtr, bool futureUse) {
swigCPtr = new HandleRef(this, cPtr);
}

protected SWIGTYPE_p_a_3__float() {
swigCPtr = new HandleRef(null, IntPtr.Zero);
}

internal static HandleRef getCPtr(SWIGTYPE_p_a_3__float obj) {
return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
}
}

請問如何將他封裝成一個偽類掉用呢?
或者使用swig 轉換的時候 能夠直接生成一個類型方法
真相重于对错 2008-05-10
  • 打赏
  • 举报
回复
intPtr
public static IntPtr UnsafeAddrOfPinnedArrayElement (
Array arr,
int index
)

111,097

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧