1 Star 0 Fork 0

2144/mono_lib

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
main.cpp 2.28 KB
一键复制 编辑 原始数据 按行查看 历史
2144 提交于 2024-10-26 12:33 . ss
#include "pch.h"
#include "Domain.h"
#include "States.h"
#pragma comment(lib, "winmm.lib")
#pragma comment(lib, "Version.lib")
#pragma comment(lib, "Bcrypt.lib")
#pragma comment(lib, "Ws2_32.lib")
int main()
{
mono::Domain::Desc desc;
desc.m_DebugName = "Hello world";
std::shared_ptr<mono::Domain> domain = std::make_shared<mono::Domain>(desc);
auto assembly = domain->OpenAssembly("../hello.dll");
auto image = assembly->CreateImage();
auto clazz = image->GetClazz("", "Helloworld");
mono::States::Register("Vec3", image->GetClazz("", "Vec3"));
auto method = clazz->GetMethod("Add", 2);
auto method2 = clazz->GetMethod("Multiply", 2);
auto method3 = clazz->GetMethod("Sub", 2);
auto method4 = clazz->GetMethod("SubData", 3);
auto method5 = clazz->GetMethod("CC", 3);
auto method6 = clazz->GetMethod("add_float", 2);
auto method7 = clazz->GetMethod("SetPos", 1);
auto obj = domain->NewInstance(*clazz);
{
int a = 11;
int b = 44;
int res = obj->InvokeMethodArgs<int>(*method2, a, b);
std::cout << "res is " << res << std::endl;
}
{
std::string s1 = "hello ";
std::string s2 = "world";
std::string res2 = obj->InvokeMethodArgs<std::string>(*method3, s1, s2);
std::cout << res2 << std::endl;
}
{
std::string s1 = "hello ";
std::string s2 = "my name is";
std::string s3 = "fbz";
std::string res = obj->InvokeMethodArgs<std::string>(*method4, s1, s2, s3);
std::cout << res << std::endl;
};
{
int a1 = 22;
int b = 2;
int c = 2;
int res = obj->InvokeMethodArgs<int>(*method5, a1, b, c);
std::cout << res << std::endl;
};
{
float a = 11.2f;
float b = 22.3f;
float res = obj->InvokeMethodArgs<float>(*method6, a, b);
std::cout << res << std::endl;
}
{
glm::vec3 pos(1.0f, 2.0f, 5.0f);
// auto clazzVec3 = clazz->GetInnerClass("Vec3");
// if(clazzVec3->m_Class)
// {
// auto obj2 = domain->NewInstance(*clazzVec3);
// }
glm::vec3 res = obj->InvokeMethodArgs<glm::vec3>(*method7, pos);
std::cout << res.x << " " << res.y << " " << res.z << " " << std::endl;
}
return 0;
};
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/iamherer/mono_lib.git
git@gitee.com:iamherer/mono_lib.git
iamherer
mono_lib
mono_lib
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385