C# 使用托管c+;包装类(本机c+;+;)+;,如何处理本机结构?
构建它,我们可以得到一个.NETDLL 创建一个C#客户端以使用此dll:C# 使用托管c+;包装类(本机c+;+;)+;,如何处理本机结构?,c#,struct,managed-c++,C#,Struct,Managed C++,构建它,我们可以得到一个.NETDLL 创建一个C#客户端以使用此dll: namespace mcWrapper { struct S1 { int n1; int n2; }; class C1 { public: void Test(S1* ps1) { }; }; public ref class Class1Wrapper { public: Class1Wrapper() { _pC1
namespace mcWrapper {
struct S1
{
int n1;
int n2;
};
class C1
{
public:
void Test(S1* ps1)
{
};
};
public ref class Class1Wrapper
{
public:
Class1Wrapper()
{
_pC1 = new C1();
};
void Test(S1* ps1)
{
_pC1->Test(ps1);
}
private:
C1* _pC1;
};}
我无法在c#中运行Class1Wrapper.Test
然后我尝试将Test()更改为Test(int^n),
我发现c#explain Test(int^n)作为Test(ValueType n)
各位,我一直很困惑。所以,我应该做的是设置一个新的托管结构,如:
//c#
public Form1()
{
InitializeComponent();
var c1 = new mcWrapper.Class1Wrapper();
//we can find Test method , but we cannot type codes like: s1*
c1.Test()//?????????????????????????????????
}
然后将测试(…)从
到
这对包装工来说是一项艰苦的工作。我认为这是在浪费时间。没有其他方法了?欢迎使用堆栈溢出!请仅对实际答案使用“发布答案”按钮。您应该修改您的问题以添加其他信息,包括此答案上的信息。恐怕没有更简单的方法。如果
S1
是一个更复杂的类,我甚至会让CsS1
包装一个S1
指针。
public value struct CsS1{int n1;int n2}
Class1Wrapper::Test(S1* ps1){_pc1->Test(ps1);}
Class1Wrapper::Test(CsS1* pcs1)
{
S1* ps1 = new S1();
ps1.n1=pcs1.n1;
ps1.n2=pcs.n2;
_pc1->Test(ps1);
delete ps1;
}