我无法将参数从C ++ / CLI代码传递到.NET C#函数。
I'm having trouble passing an argument from C++/CLI code into a .NET C# function.
在C ++中,我有类似以下的东西:
In C++ I have something resembling the following:
void SomeFunction(short *id) { CSharpClass::StaticClassInstance->SetValue(id); }在C#方面,函数声明为ref参数: / p>
On the C# side, the function is declared with a ref argument as:
public void SetValue(ref short id) { id = this.internalIdField; }调用SetValue(id)时遇到的编译器错误是can not将参数1从short *转换为short%。
The compiler error I'm getting when calling SetValue(id) is "cannot convert parameter 1 from 'short *' to 'short %'".
我发现跟踪引用(%)等效于C#ref,但我不知道如何使用short *参数我试图
I found out that a tracking reference (%) is equivalent to C# ref but I don't know how to use it with the short* parameter I'm trying to pass.
提前感谢。
推荐答案逻辑C ++ / CLI的签名 CSharpClass :: SetValue 是
The logical C++/CLI signature of CSharpClass::SetValue is
void SetValue(short% id);如果你知道C ++(而不是C ++ / CLI),这里的答案是完全相同的这将是如果你有C + +签名
If you know C++ (as opposed to C++/CLI), the answer here is the exact same as it would be if you had the C++ signature
void SetValue(short& id);即,只需取消引用指针:
I.e., simply dereference the pointer:
void SomeFunction(short *id) { CSharpClass::StaticClassInstance->SetValue(*id); }更多推荐
如何传递C ++ short *到C ++ / CLI中的托管C#程序集
发布评论