问题说明
我在运行时组件中有一个公共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 *'
我该怎么办?
是否有类型或方式而不是指针?
答案 0 :(得分:0)
怎么样......
[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));
}