How to pass a C++ short* to managed C# assembly in C++/CLI

≡放荡痞女 提交于 2019-12-05 22:42:39

The logical C++/CLI signature of CSharpClass::SetValue is

void SetValue(short% id);

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);
}

If you want to be long winded, declare a tracking reference, assign the tracking reference to your id parameter and then pass the tracking reference to your function...

short %s = *id;

SetValue (s);

If you'd rather not be long winded, just dereference the pointer. While the compiler cannot convert a short * into a short % it can convert a short into a short %...

SetValue (*id);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!