1

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.

John Saunders
  • 157,405
  • 24
  • 229
  • 388
Synetech
  • 8,907
  • 7
  • 59
  • 90

2 Answers2

4
prot = new LowLevelMouseProc(HookCallBack);
John Saunders
  • 157,405
  • 24
  • 229
  • 388
3

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);
bdukes
  • 137,241
  • 21
  • 139
  • 173
  • Thanks a lot, that worked and makes sense. (I’m from C++, so I’ve done very little in C#). Thanks again. – Synetech Jul 20 '09 at 16:36