外部功能-C# [英] external functions - c#

查看:84
本文介绍了外部功能-C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在研究外部函数时遇到了这个问题.
关于使用非托管DLL的外部函数的以下哪些陈述是正确的?
1-无法调用需要将结构作为参数传递的外部函数.
2-无法调用需要将回调函数作为参数传递的外部函数.

你知道答案吗?
谢谢

I came across this question while studying extern functions.
Which of the following statements about using external functions from unmanaged DLLs are true?
1 - External functions which require a structure to be passed as a parameter cannot be called.
2 - External functions which require a callback function to be passed as a parameter cannot be called.

Do you know the answer please?
Thanks

推荐答案

1绝对不是正确的.您可以在托管代码中定义结构,然后调用extern 方法 [ ^ ].

在.Net 2.0中可能是2,但在1.1中是不可能.
.Net 2.0包含UnmanagedFunctionPointerAttribute属性,该属性使我们可以将委托传递给不受管理的代码 [^ ].

因此,基本上,AFAIK,2将是.Net 1.1的正确答案.
但是对于.Net 2.0及更高版本,两者都是不正确的.

好问题.让我思考(和阅读)了一段时间.
1 is definitely not true. You can define a structure in managed code and call the extern method[^].

2 is possible in .Net 2.0 but not in 1.1.
.Net 2.0 contains a UnmanagedFunctionPointerAttribute attribute which allows us to pass a delegate to unmanaged code[^].

So basically, AFAIK, 2 would be the right answer for .Net 1.1.
But for .Net 2.0 and beyond, both would be incorrect.

Good question. Had me thinking (and reading) a while.


这篇关于外部功能-C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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