将 C# Delegates 从 2005 项目转换为 C# 2003

发布于 2024-07-27 22:21:51 字数 756 浏览 5 评论 0原文

我正在尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

丢了幸福的猪 2024-08-03 22:21:52
prot = new LowLevelMouseProc(HookCallBack);
prot = new LowLevelMouseProc(HookCallBack);
手长情犹 2024-08-03 22:21:52

看起来它正在使用 HookCallback 作为委托。 在 C# 1 中,您必须使用委托构造函数创建委托,不能只使用方法名称 (就像在 C# 2+ 中一样)。

查看 proc 的类型,并使用它来创建新的委托,如下所示:

proc = new LowLevelMouseProc(HookCallBack);

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:

proc = new LowLevelMouseProc(HookCallBack);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文