将 C# Delegates 从 2005 项目转换为 C# 2003
我正在尝试在 VS2003 中编译在 C# 2005 中创建的 MouseTracking 项目。除了一行之外,我已将其修复:
proc = HookCallback;
这给出了错误 不带括号引用的方法“MouseTracking.MouseTracker.HookCallback(int, System.IntPtr, System.IntPtr)”
如果我向 HookCallback 添加括号,则会得到 方法“HookCallback”没有重载,需要“0”参数
我尝试将函数参数添加为类型、变量名称以及两者,但似乎都不起作用。
以下是相关定义:
private LowLevelMouseProc proc;
private delegate IntPtr LowLevelMouseProc (int nCode, IntPtr wParam, IntPtr lParam);
private IntPtr HookCallback (int nCode, IntPtr wParam, IntPtr lParam) {…}
知道如何编译它吗? 我真的很想添加和调整一些东西。
多谢。
I’m trying to compile in VS2003 that MouseTracking project that was made in C# 2005. I’ve got it fixed up except for one line:
proc = HookCallback;
This gives the error Method 'MouseTracking.MouseTracker.HookCallback(int, System.IntPtr, System.IntPtr)' referenced without parentheses
If I add parantheses to HookCallback, I get No overload for method 'HookCallback' takes '0' arguments
I have tried adding the function arguments as types, variable names, and both, but none seem to work.
Here are the relevant definitions:
private LowLevelMouseProc proc;
private delegate IntPtr LowLevelMouseProc (int nCode, IntPtr wParam, IntPtr lParam);
private IntPtr HookCallback (int nCode, IntPtr wParam, IntPtr lParam) {…}
Any idea how to get this to compile? I’d really like to add and tweak a few things.
Thanks a lot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来它正在使用 HookCallback 作为委托。 在 C# 1 中,您必须使用委托构造函数创建委托,不能只使用方法名称 (就像在 C# 2+ 中一样)。
查看 proc 的类型,并使用它来创建新的委托,如下所示:
It looks like it's using HookCallback as a delegate. In C# 1 you have to create delegates using a delegate constructor, you can't just use the method name (like you can in C# 2+).
Take a look at the type of
proc
, and use that to create a new delegate, like so: