我如何在C#中调用一个在编译时未知的本机函数 [英] How can i invoke a during compiletime unknown native function from C#

查看:91
本文介绍了我如何在C#中调用一个在编译时未知的本机函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在运行时,系统会为我提供一个String名称,一个排序的对象数组以及一些有关本机函数的附加信息(dllpath,calltype等).

During runtime i am supplied with a String name, a sorted array of objects and some additional information about a native function (dllpath, calltype, etc).

让我们假设所有信息都在CallInformation对象中.

lets assume all information was in a CallInformation Object.

如何调用此本机函数?

注意: -运行时之前没有提供dll. -运行时之前未向我提供呼叫信息. -在运行时之前,我不知道调用参数的数量或类型. -在运行时之前我不知道返回类型.

note: - i am not supplied with the dll before runtime. - i am not supplied with the call information before runtime. - i dont know the ammount or types of call parameter before runtime. - i dont know the returntype before runtime.

网络上的常规信息关于调用本机函数的处理与调用

The usual information on the web about calling native functions deals with invoking

  • 已知dll中的已知功能类型
  • 未知dll中的已知功能类型

我需要的是

  • 未知dll中的未知功能类型

推荐答案

该解决方案将涉及Reflection.Emit.您必须根据CallInformation动态生成一个类,该类包含装饰有适当DllImport属性的PInvoke签名. 抱歉,没有代码,但考虑到冗长的Reflection.Emit API,就不能将其归结为值得发布的内容.

The solution would involve Reflection.Emit. You have to dynamically generate a class containing your PInvoke signature decorated with the appropriate DllImport attribute based on your CallInformation. Sorry that there is no code, but it can't be boiled down to something worthy to post, considering the verbose Reflection.Emit API.

这篇关于我如何在C#中调用一个在编译时未知的本机函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆