如何传递C ++ short *到C ++ / CLI中的托管C#程序集

编程入门 行业动态 更新时间:2024-10-17 17:28:40
本文介绍了如何传递C ++ short *到C ++ / CLI中的托管C#程序集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我无法将参数从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#程序集

本文发布于:2023-11-13 14:54:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1584633.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:程序   short   CLI

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!