将委托从C#转换为VB.NET

将委托从C#转换为VB.NET,c#,vb.net,events,delegates,handler,C#,Vb.net,Events,Delegates,Handler,我正试图将我的C#代码转换为VB.NET,但我被卡住了 我收到的错误是“Private Event FixationReceived(Byref data作为Fixation,userdata作为System.IntPtr)是一个事件,无法直接调用。请使用RaiseEvent引发事件 我最初的C#代码是: 这就是我设置委托处理程序的方式: FixationReceived += new FixationDelegate(SharpClient_FixationReceived);

我正试图将我的C#代码转换为VB.NET,但我被卡住了

我收到的错误是“Private Event FixationReceived(Byref data作为Fixation,userdata作为System.IntPtr)是一个事件,无法直接调用。请使用RaiseEvent引发事件

我最初的C#代码是:

这就是我设置委托处理程序的方式:

    FixationReceived += new FixationDelegate(SharpClient_FixationReceived);

    IntPtr p;
    p = Marshal.GetFunctionPointerForDelegate(FixationReceived);
    _api.SetFixationCB(p.ToInt32(), IntPtr.Zero);


    private void SharpClient_FixationReceived(ref Fixation data, IntPtr userData)
    {          
        if (InvokeRequired)
        {
            BeginInvoke(new FixationDelegate(SharpClient_FixationReceived), new object[] { data, userData });
        }
        else
        {
            eventStreamLabel.Text = "Fix Start: " + data.timeStamp.ToString() + " Duration: " + data.duration.ToString();              
        }            
    }
Dim p As IntPtr
'In the next line the stated error is raised
p = Marshal.GetFunctionPointerForDelegate(FixationReceived)
_api.SetFixationCB(p.ToInt32(), IntPtr.Zero) 'this works fine

AddHandler(FixationEvent, AddressOf VBNET_FixationReceived )'here I am getting the error "FixationEvent is not an event of MyApplication.Form1"
BeginInvoke(New fixationDelegate(AddressOf vbnet_fixationreceived )'Here I get an error without any further explanation.
我尝试使用以下方法将其转换为VB.NET:

Private Event FixationReceived As FixationDelegate

Private Sub VBNET_FixationReceived(ByRef data As Fixation, userData As System.IntPtr)

    Stop'is never called :-(

End Sub
我就是这样设置处理程序的:

    FixationReceived += new FixationDelegate(SharpClient_FixationReceived);

    IntPtr p;
    p = Marshal.GetFunctionPointerForDelegate(FixationReceived);
    _api.SetFixationCB(p.ToInt32(), IntPtr.Zero);


    private void SharpClient_FixationReceived(ref Fixation data, IntPtr userData)
    {          
        if (InvokeRequired)
        {
            BeginInvoke(new FixationDelegate(SharpClient_FixationReceived), new object[] { data, userData });
        }
        else
        {
            eventStreamLabel.Text = "Fix Start: " + data.timeStamp.ToString() + " Duration: " + data.duration.ToString();              
        }            
    }
Dim p As IntPtr
'In the next line the stated error is raised
p = Marshal.GetFunctionPointerForDelegate(FixationReceived)
_api.SetFixationCB(p.ToInt32(), IntPtr.Zero) 'this works fine

AddHandler(FixationEvent, AddressOf VBNET_FixationReceived )'here I am getting the error "FixationEvent is not an event of MyApplication.Form1"
BeginInvoke(New fixationDelegate(AddressOf vbnet_fixationreceived )'Here I get an error without any further explanation.
我没有将C#委托转换为VB.NET的经验,也许有人能解释一下我的错误

非常感谢!

试试这个

AddHandler FixationDelegate, AddressOf SharpClient_FixationReceived

Dim p As IntPtr
p = Marshal.GetFunctionPointerForDelegate(FixationReceived)
_api.SetFixationCB(p.ToInt32(), IntPtr.Zero)
-


我真的不明白否决票。我听说过VB.NET到C,但从来没有听说过C到VB.NET。你有没有试过使用一个免费的反编译器查看你的C编译程序集,它可以让你在C和VB之间切换反汇编源代码视图?这可能对你的转换工作很方便。我收到了错误“Private Event FixationReceived”(ByRef数据作为固定,userData作为System.IntPtr)“是一个事件,不能直接调用。请使用RaiseEvent来引发事件。”在您的行中,p=Marshal.GetFunctionPointerForDelegate(FixationReceived)