如何在运行时组件中返回指针类型
本文关键字:返回 指针 类型 组件 运行时 | 更新日期: 2023-09-27 18:20:07
问题描述
我在运行时组件中有一个公共api,我希望它的公共成员可以返回一个pointer type
,例如:
namespace WinRt
{
public value struct struct_instance_t{};
class classTest
{
struct_instanst_t* RuntimeApi() {
return otherCApi(); // other_namespace::struct_instanst_t* otherCApi()
}
};
}
我的问题
它有一个编译错误,比如:
error C3992: 'vadNew': signature of public member contains invalid type 'WinRt::struct_instance_t *'
我该怎么办?
是否有一种类型或方式来代替指针?
怎么样。。。
[System.Runtime.InteropServices.DllImportAttribute("YourC++.dll", EntryPoint="otherCApi")]
public static extern System.IntPtr otherCApi() ;
public static struct_instance_t RuntimeApi() {
IntPtr ptr = otherCApi();
return (struct_instanst_t)(Marshal.PtrToStructure(ptr, typeof(struct_instanst_t));
}