在c# Unity3d中添加静态c++库
DllImport static C++ library in C# Unity3d
对于函数的简单签名,只需:
[DllImport("__Internal")]
public static extern MyFunc(int a);
如何实现
的功能static App* Create(const AppOptions& options, JNIEnv* jni_env,
jobject activity);
c++中的指针和引用如何替换为c# ?
您需要使用封送处理。
例子:
/* unmanaged code declarations */
struct UnmanagedStruct {
int n;
};
void PassByValue (struct UnmanagedStruct s);
void PassByReferenceIn (struct UnmanagedStruct *s);
void PassByReferenceOut (struct UnmanagedStruct *s);
void PassByReferenceInOut (struct UnmanagedStruct *s);
struct UnmanagedStruct ReturnByValue ();
struct UnmanagedStruct* ReturnByReference ();
void DoubleIndirection (struct UnmanagedStruct **s);
类包装器可以是:
/* note: sequential layout */
[StructLayout (LayoutKind.Sequential)]
class ClassWrapper {
public int n;
/* cannot wrap function PassByValue */
/* PassByReferenceIn */
[DllImport ("mylib")]
public static extern
void PassByReferenceIn (ClassWrapper s);
/* PassByReferenceOut */
[DllImport ("mylib")]
public static extern
void PassByReferenceOut ([Out] ClassWrapper s);
/* PassByReferenceInOut */
[DllImport ("mylib")]
public static extern
void PassByReferenceInOut ([In, Out] ClassWrapper s);
/* cannot wrap function ReturnByValue */
/* ReturnByReference */
[DllImport ("mylib")]
public static extern ClassWrapper ReturnByReference ();
/* note: this causes returned pointer to be freed
by runtime */
/* DoubleIndirection */
[DllImport ("mylib")]
public static extern
void DoubeIndirection (ref ClassWrapper s);
}
下面是一些有用的链接:
- 与本地库互操作 c#的封送处理
- 对象默认封送
相关文章:
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- #为""定义宏;静态";针对不同的上下文
- cmake如何在fedora工作站中找到boost静态库包
- 静态数据成员的问题-修复链接错误会导致编译器错误
- 将公共但非静态的成员函数与ALGLIB集成
- cmake在我的项目中所需的所有静态库都不成功
- C++从另一个类访问公共静态向量的正确方法是什么
- 基于boost的程序的静态链接——zlib问题
- 在静态库中嵌入类方法
- Qt C++静态thread_local QNetworkAccessManager是线程应用程序的好选择吗
- 如何在C++中获得"静态纯虚拟"功能?
- 私有类型的静态常量成员
- 使用gcc从静态链接的文件中查找可选符号
- 在 .h 文件中的类中声明静态变量和在.cpp文件中声明"global"变量有什么区别
- 如何在C++中使用非静态成员函数作为回调函数
- 将静态库链接到不带-fPIC的共享库中
- 静态结构和一个定义规则
- 为什么虚函数不能是静态的和全局的?
- C++17中函数模板中的静态数组初始化(MSVC 2019)
- 停止cmake target_link_libraries将插件中静态库的两个对象文件链接到静态库本身