如何在运行时组件中返回指针类型
how to return a pointer type in runtime component?
问题描述
我在运行时组件中有一个公共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));
}
相关文章:
- 在函数中返回无符号字符数组,但不返回指针
- 为什么需要返回指针来利用协方差?
- 野牛如何在解析树中返回指针
- 何时返回指针与返回对象的一般经验法则?
- 为什么使用 std::istream_iterator 构造函数返回指针
- 为什么我不能直接从返回指针的函数返回对指针的引用?
- 如何在不使用临时变量的情况下取消引用返回指针的函数的返回值?
- 为什么下面的代码段返回指针指向的值而不是指针的地址?
- 使用 map<char,strring> 的迭代器返回指针 map<char,strring>*
- 如何从类成员函数返回指针,例如 size_t * class :: function(); 并使用类析构函数 ~size
- 函数返回动态强制转换的指针,返回指针,就好像它根本没有被转换一样
- 从函数返回对指针的引用与返回指针相同?
- C++ 为什么访问数组中的元素会返回指针?
- 关于函数返回指针
- 返回指针或对私有成员的引用的替代方法
- 从函数返回指针
- 通过从当地的C风格阵列中返回指针来获取一个悬空的指针
- 我应该如何定义返回指针的函数?(引用指针与指针指针)
- 为什么C 模板功能不支持返回指针
- 返回指针的语句 - 解释它是如何工作的以及为什么