|
|
 | | From: | =?Utf-8?B?5Ya35p6r?= | | Subject: | =?Utf-8?B?6auY5omL6K+36L+b77yaQyPoo4XphY3ku7bosIPnlKhNYW5hZ2VkQysr?= | | Date: | Wed, 19 Jan 2005 23:45:02 -0800 |
|
|
 | C#装配件调用ManagedC++装配件时,数组怎么传递的? 如以下的代码。
Manged C++中, #pragma once #using #include "StdAfx.h" public __gc class MyMathTool { public: //判断一个点是否在多边形内 int PointAndPoly(double x, double y, int np, double* xp, double* yp) { return 0; } }
C#中某个类的一个函数,调用上面那个装配件: void myFunc() { double x; double y; int np = 10; double[] xp = new double[np]; double[] yp = new double[np]; MyMathTool.PointAndPoly(x, y, np, xp, yp); }
编译出错。应该怎么样写呢?
谢谢!
|
|
 | | From: | Jacky Kwok | | Subject: | Re: =?UTF-8?B?6auY5omL6K+36L+b77yaQyPoo4XphY3ku7bosIPnlKhNYW5hZ2U=?= | | Date: | Thu, 20 Jan 2005 17:23:44 +0800 |
|
|
 | 冷枫 wrote: > C#装配件调用ManagedC++装配件时,数组怎么传递的? 如以下的代码。 > > Manged C++中, > #pragma once > #using > #include "StdAfx.h" > public __gc class MyMathTool > { > public: > //判断一个点是否在多边形内 > int PointAndPoly(double x, double y, int np, double* xp, double* yp) > { > > return 0; > } > } > > C#中某个类的一个函数,调用上面那个装配件: > void myFunc() > { > double x; double y; > int np = 10; > double[] xp = new double[np]; > double[] yp = new double[np]; > MyMathTool.PointAndPoly(x, y, np, xp, yp); > } > > 编译出错。应该怎么样写呢? > > 谢谢!
From C# calling to MC++, the array in C# is managed arrag You should define
public __gc class MyMathTool { public:
int PointAndPoly(double x, double y, int np, double xp __gc[], double yp __gc[]) { ....
"double xp __gc[]" is a managed array type, it has a count member. In fact, you are not necessary to pass the "int np".
An example to get the sum of double __gc[],
double Class1::Sum1(double array __gc[]) { int len = array->Count; double sum=0.0; for (int i=0; i sum += array[i];
return sum; }
-- Jacky Kwok jacky@alumni_DOT_cuhk_DOT_edu_DOT_hk jacky@compose_DOT_com_DOT_hk
|
|
 | | From: | =?Utf-8?B?5Ya35p6r?= | | Subject: | =?Utf-8?B?UmU6IOmrmOaJi+ivt+i/m++8mkMj6KOF6YWN5Lu26LCD55SoTWFuYWdlZA==?= | | Date: | Thu, 20 Jan 2005 02:33:01 -0800 |
|
|
 | Thanks a great deal. I solved the problem using your method, thank you.
“Jacky Kwok”编写:
> 冷枫 wrote: > > C#装配件调用ManagedC++装配件时,数组怎么传递的? 如以下的代码。 > > > > Manged C++中, > > #pragma once > > #using > > #include "StdAfx.h" > > public __gc class MyMathTool > > { > > public: > > //判断一个点是否在多边形内 > > int PointAndPoly(double x, double y, int np, double* xp, double* yp) > > { > > > > return 0; > > } > > } > > > > C#中某个类的一个函数,调用上面那个装配件: > > void myFunc() > > { > > double x; double y; > > int np = 10; > > double[] xp = new double[np]; > > double[] yp = new double[np]; > > MyMathTool.PointAndPoly(x, y, np, xp, yp); > > } > > > > 编译出错。应该怎么样写呢? > > > > 谢谢! > > > From C# calling to MC++, the array in C# is managed arrag > You should define > > public __gc class MyMathTool > { > public: > > int PointAndPoly(double x, double y, int np, > double xp __gc[], > double yp __gc[]) > { > .... > > > "double xp __gc[]" is a managed array type, it has a count member. In > fact, you are not necessary to pass the "int np". > > An example to get the sum of double __gc[], > > double Class1::Sum1(double array __gc[]) > { > int len = array->Count; > double sum=0.0; > for (int i=0; i> sum += array[i]; > > return sum; > } > > > > > > > > > > > > -- > Jacky Kwok > jacky@alumni_DOT_cuhk_DOT_edu_DOT_hk > jacky@compose_DOT_com_DOT_hk >
|
|
|