views:

105

answers:

2

Hi,

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.

+4  A: 
prot = new LowLevelMouseProc(HookCallBack);
John Saunders
+3  A: 

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
Thanks a lot, that worked and makes sense. (I’m from C++, so I’ve done very little in C#).Thanks again.
Synetech inc.