1

I'm trying to use this code, which is in C#, in VB.NET. The code's purpose is to read the mouse coordinates and output them when you click the mouse button, using a Console application. Yes, I realise this is a stupid use of a Console application, but it may be necessary for a project I want to undertake. I've managed to make it work in C#, but in VB.NET I get an error in this area:

Private Shared _proc As LowLevelMouseProc = HookCallback()

The C# line is:

private static LowLevelMouseProc _proc = HookCallback;

The HookCallback function has three parameters, I've included the code below:

private static IntPtr HookCallback(
        int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode >= 0 &&
                MouseMessages.WM_LBUTTONDOWN == (MouseMessages)wParam)
            {
                MSLLHOOKSTRUCT hookStruct = (MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT));
                Console.WriteLine(hookStruct.pt.x + ", " + hookStruct.pt.y);
            }
            return CallNextHookEx(_hookID, nCode, wParam, lParam);
        }

For some reason in the C# code, it calls the HookCallback function with no parameters listed and this is absolutely fine. In VB.NET, this doesn't work, as I would expect. My question is: how can I make this work in VB.NET? I'm new to C#, otherwise I would use the C# code.

4

0 回答 0