How can i invoke a during compiletime unknown nati

2019-07-18 23:52发布

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).

lets assume all information was in a CallInformation Object.

How can i call this native function?

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

  • known functionstypes in known dlls
  • known functionstypes in unknown dlls

What i need is

  • unknown functionstypes in unknown dlls

2条回答
疯言疯语
2楼-- · 2019-07-19 00:18

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.

查看更多
迷人小祖宗
3楼-- · 2019-07-19 00:20

Make a delegate signature dynamically and call it using reflection.
Just look up how to create delegates dynamically, how to load a native function, how to call a function using reflection and connect those together.

查看更多
登录 后发表回答