使用C ++ / CLI包装本机C ++类 [英] Use C++/CLI to wrapper native C++ class
问题描述
我使用C ++ / CLI来包装本机C ++类。我在C#中使用了包装类。
C ++本机类的一个方法有以下声明:
void Test(int * pnNum1,int * pnNum2);
方法C ++ / CLI托管类的测试具有以下声明:
voidТest([Out] interior_ptr< int> pnNum1,[Out] interior_ptr< int> pnNum2);参数pnNum1和pnNum2通过引用传递。
void ManageClass :: Test [Out] interior_ptr< int> pnNum1,[Out] interior_ptr< int> pnNum2)
{
NativeClassPtr-> Test((int *)& pnNum1,(int *)& pnNum2); // 不起作用!!!
}
如何通过引用Test NativeClassPtr-> Test?方法传递参数?
我必须转换为 interior_ptr到pin_ptr到native_ptr。 H 不使用变量(pin_ptr是原生的)来做到这一点。
试试这个:
<跨度>&NBSP;&NBSP;
pin_ptr < int > pp1 =
pnNum1 ;
pin_ptr < int > pp2 =
pnNum2 ;
NativeClassPtr->测试(pp1,pp2);
I am use C++/CLI to wrapper native C++ class. I'm use wrapper class in C#.
One the methods of the C++ native class has the following declaration:
void Test(int *pnNum1, int *pnNum2);
The method Test of the C++/CLI managed class has the following declaration:
void Тest([Out]interior_ptr<int> pnNum1, [Out]interior_ptr<int> pnNum2); The parameter pnNum1 and pnNum2 passing by reference.
void ManageClass::Test[Out]interior_ptr<int> pnNum1, [Out]interior_ptr<int> pnNum2)
{
NativeClassPtr->Test((int *)&pnNum1, (int *)&pnNum2); //did not work!!!
}
How do I pass a parameter by reference of the method Test NativeClassPtr->Test?
I have to convert to interior_ptr to pin_ptr to native_ptr. How to do this without using variables(pin_ptr an native).Try this:
pin_ptr<int> pp1 = pnNum1;
pin_ptr<int> pp2 = pnNum2;
NativeClassPtr->Test( pp1, pp2 );
这篇关于使用C ++ / CLI包装本机C ++类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!