Ciao a tutti,
dovrei portare in c# del codice Vb.Net, per la comunicazione tramite USB...
In particolare devo "intercettare" il medodo WinProc tramite delegate, il codice VB è questo:

Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Integer, ByVal hwnd As Integer, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hwnd As Integer, ByVal nIndex As Integer, ByVal dwNewLong As Integer) As Integer

Delegate Function SubClassProcDelegate(ByVal hwnd As Integer, ByVal msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Public Declare Function DelegateSetWindowLong Lib "USER32.DLL" Alias "SetWindowLongA" _
(ByVal hwnd As Integer, ByVal attr As Integer, ByVal lval As SubClassProcDelegate) As Integer
...
Private Ref_WinProc As New SubClassProcDelegate(AddressOf WinProc)

...
Public Function ConnectToHID(ByRef targetForm As Form) As Boolean
Dim pHostWin As Integer = targetForm.Handle.ToInt32
FWinHandle = pHostWin
pHostWin = hidConnect(FWinHandle)
FPrevWinProc = DelegateSetWindowLong(FWinHandle, GWL_WNDPROC, Ref_WinProc)
HostForm = targetForm
End Function

L'ho tradotto in questo modo:
[DllImport("user32.dll", EntryPoint = "CallWindowProcA")]
public static extern int callWindowProc(int lpPrevWndFunc, int hwnd, int Msg, int wParam, int lParam);
[DllImport("user32.dll", EntryPoint = "SetWindowLongA")]
public static extern int setWindowLong(int hwnd, int nIndex, int dwNewLong);

public delegate int SubClassProcDelegate(int hwnd, int msg, int wParam, int lParam);
DllImport("user32.dll", EntryPoint = "SetWindowLongA")]
public static extern int delegateSetWindowLong(int hwnd, int attr, SubClassProcDelegate lval);
la dichiarazione di SubClassProcDelegate mi da errore dicendo che il metodo deve avere un tipo restituito (ed io ho appunto messo int)

private SubClassProcDelegate Ref_WinProc = new SubClassProcDelegate(WndProc);


Mi da errore perchè non so come tradutte l'AddressOf e lasciando solamente WndProc non mi va ontretutto non so come settare la "using" per farglielo riconoscere?

public HIDDLLInterface(ref Form targetForm) {
HostForm = targetForm;
FWinHandle = targetForm.Handle.ToInt32();
FPrevWinProc = delegateSetWindowLong(FWinHandle, GWL_WNDPROC, Ref_WinProc);
}


Qualcuno ha idea di come fare? Esiste WinProc in C# perchè io ho trovato solamente WndProc, ma ha una firma diversa (un solo parametro da passare...)