c# - 动态添加 UnmanagedFunctionPointerAttribute 到委托
问题描述
我有一个 CreateDelegate 方法,我使用
Marshal.GetDelegateForFunctionPointer(func_addr, CreateDelegate())
它工作得很好,但现在我需要将其作为 ThisCall 进行编组。所以 func_addr 是一个“CallingConvention.ThisCall”。静态地,这是有效的:
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
delegate int d_Add(IntPtr _this, int x, int y);
...
var value = Marshal.GetDelegateForFunctionPointer<d_Add>(Addfunc_addr)(_this, 50, 100);
// return 150;
我想在运行时将 UnmanagedFunctionPointerAttribute 添加到来自 CreateDelegate 的新委托,或者以任何方式将我的委托编组为 ThisCall,这可能吗?
我找到了这个线程:在运行时添加自定义属性,但在我的情况下它不是自定义属性。
解决方案
推荐阅读
- amazon-web-services - 仅在 Aurora 事务提交时调用 Lambda 函数,但保证调用 (ACID)
- python - 在 Linux CLI 中更改 XLS 单元格值而不破坏格式
- javascript - Rails-Jquery Uncaught ReferenceError: $ is not defined
- amazon-web-services - AWS CodeDeploy 优点/缺点
- javascript - 如何创建一个在到达终点时反转的暂停的循环 react-redux
- unity3d - 在按钮文本的范围内单击会触发按钮
- assembly - 为什么某些二进制文件中没有显示“动态链接的函数名称”?
- linq - Linq 结果类型?
- javascript - javascript 上的数组减少返回具有数组可链接性的错误值
- python - 在 Visual Studio 2017 中运行 Python,输出显示不正确?