【问题标题】:Converting AddressOf from VB6 to c#将 AddressOf 从 VB6 转换为 c#
【发布时间】:2013-07-30 12:20:06
【问题描述】:

在 VB6 中,我们有以下代码。

g_CTimer.TimerID = SetTimer(0&, 0&, g_CTimer.Interval, AddressOf TimerProc)

TimerProc方法如下

Sub TimerProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, ByVal dwTime As Long)
    On Error Resume Next

    If g_CTimer Is Nothing Then Exit Sub
    g_CTimer.ThatTime

End Sub

我们如何在 C# 中转换该调用“AddressOf TimerProc”。

提前致谢。

问候 阿秋斯

【问题讨论】:

  • 删除它。方法组被隐式转换为委托。 [SetTimer(0, 0, g_CTimer.Interval, TimerProc)]
  • 使用pinvoke.net 网站查找正确的声明。但是,请不要为此烦恼,.NET Timer 类已经为您处理好了。

标签: c# vb6-migration addressof


【解决方案1】:

在 C# 中,您可以省略 AddressOf 关键字。在 VB.NET 中,它明确暗示您将方法指针作为参数发送(在本例中为指向 TimerProc 的指针)。在 C# 中,您可以直接使用方法名称。

也就是说,您最好使用普通计时器(Windows.Forms.Timer 或其他)重新实现它。

【讨论】:

  • @Achyuth 你仍然有四个参数 - AddressOf TimerProc 是一个参数,你用TimerProc 替换它。
猜你喜欢
  • 2011-10-29
  • 1970-01-01
  • 2011-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-10
  • 1970-01-01
相关资源
最近更新 更多