[英]c++ wrapping to c# by passing handle decelrator
I have a function in c++ like this which has another function inside it like this: 我在C ++中有一个像这样的函数,里面有另一个函数,像这样:
Doom(int n, const array<double> ^x, int incx, int k, double r){
pin_ptr<double> xptr = &(x[0]);
fdoom(n, xptr, incx, &k, &r, &fail);
}
now when I call this function from c#: 现在,当我从c#调用此函数时:
int k = 0;
double r = 0.0;
CPPCode.Doom(n, x, incx, k, r);
here my values k and r should change to 1 and -2 but this doesn't happen. 在这里,我的值k和r应该更改为1和-2,但这不会发生。 So I have to use refrence for this to happenbut I am totally confused about how to use CLR reference for a single value.
所以我必须使用Refreence来实现,但是我对于如何对单个值使用CLR引用感到完全困惑。
note that the function fdoom is defined like this in it's class: 请注意,函数fdoom在其类中的定义如下:
void fdoom (Integer n, const double x[], Integer incx,
Integer *k, double *r, NagError *fail)
In managed C++ you should use %
if you want to call it by reference from C#. 在托管C ++中,如果要通过C#引用进行调用,则应使用
%
。 That is your function look likes this: 那就是你的函数看起来像这样:
Doom(int n, const array<double> ^x, int incx, int %k, double r){
pin_ptr<double> xptr = &(x[0]);
pin_ptr<int> kptr = &k;
fdoom(n, xptr, incx, kptr, &r, &fail);
}
and in your C# function you should use ref
keyword to call it by reference. 在您的C#函数中,您应该使用
ref
关键字通过引用来调用它。 That is: 那是:
CPPCode.Doom(n, x, incx, ref k, r);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.