C#的一段代码不知该怎么转成VB
public delegate void WndProcEventHandler(IntPtr Handle, IntPtr Message, IntPtr wParam, IntPtr lParam);public event WndProcEventHandler CallWndProc;
public override void ProcessWindowMessage(ref System.Windows.Forms.Message m)
{
if (m.Msg == _MsgID_CallWndProc)
{
_CacheHandle = m.WParam;
_CacheMessage = m.LParam;
}
else if (m.Msg == _MsgID_CallWndProc_Params)
{
if (CallWndProc != null && _CacheHandle != IntPtr.Zero && _CacheMessage != IntPtr.Zero)
CallWndProc(_CacheHandle, _CacheMessage, m.WParam, m.LParam);
_CacheHandle = IntPtr.Zero;
_CacheMessage = IntPtr.Zero;
}
else if (m.Msg == _MsgID_CallWndProc_HookReplaced)
{
if (HookReplaced != null)
HookReplaced();
}
}
//CallWndProc != null 这一句不会理解,大人帮忙 --------------------编程问答--------------------
Public Delegate Sub WndProcEventHandler(ByVal Handle As IntPtr, ByVal Message As IntPtr, ByVal wParam As IntPtr, ByVal lParam As IntPtr)--------------------编程问答-------------------- 給你這個,http://labs.developerfusion.co.uk/convert/csharp-to-vb.aspx。
Public Event CallWndProc As WndProcEventHandler
Public Overloads Overrides Sub ProcessWindowMessage(ByRef m As System.Windows.Forms.Message)
If m.Msg = _MsgID_CallWndProc Then
_CacheHandle = m.WParam
_CacheMessage = m.LParam
ElseIf m.Msg = _MsgID_CallWndProc_Params Then
If CallWndProc IsNot Nothing AndAlso _CacheHandle <> IntPtr.Zero AndAlso _CacheMessage <> IntPtr.Zero Then
CallWndProc(_CacheHandle, _CacheMessage, m.WParam, m.LParam)
End If
_CacheHandle = IntPtr.Zero
_CacheMessage = IntPtr.Zero
ElseIf m.Msg = _MsgID_CallWndProc_HookReplaced Then
RaiseEvent HookReplaced()
End If
End Sub
有了這個以後就方便了。 --------------------编程问答-------------------- http://labs.developerfusion.co.uk/convert/csharp-to-vb.aspx
--------------------编程问答-------------------- 呵呵~先谢谢
转出来有问题哦:
If CallWndProc IsNot Nothing AndAlso _CacheHandle <> IntPtr.Zero AndAlso _CacheMessage <> IntPtr.Zero Then
CallWndProc(_CacheHandle, _CacheMessage, m.WParam, m.LParam)
End If
这个地方 :
CallWndProc IsNot Nothing '//提示说:是事件,不能直接调用
在C#里应该是委托的比较吧?VB里有委托的比较吗? --------------------编程问答-------------------- CallWndProc != null 這句翻譯得有點問題.
試試這句看看.
CallWndProc Is Not DBNull.Value --------------------编程问答-------------------- 楼上的也不对哦~ --------------------编程问答-------------------- 是不是等同于VB的RaiseEvent?只是用来引发事件?
--------------------编程问答-------------------- 你可以编译后用reflector来转 --------------------编程问答-------------------- 你把CallWndProc IsNot Nothing AndAlso 去掉.
直接If _CacheHandle <> IntPtr.Zero AndAlso _CacheMessage <> IntPtr.Zero Then --------------------编程问答-------------------- 先谢楼上的,正有此意.
你可以编译后用reflector来转
-------------------------
不失为一种好方法:)试验一下先 --------------------编程问答-------------------- 以后要转C#代码就去http://labs.developerfusion.co.uk/convert/csharp-to-vb.aspx这个网站 --------------------编程问答--------------------
--------------------编程问答-------------------- C#
Public Delegate Sub WndProcEventHandler(ByVal Handle As IntPtr, ByVal Message As IntPtr, ByVal wParam As IntPtr, ByVal lParam As IntPtr)
Public Event CallWndProc As WndProcEventHandler
Public Overloads Overrides Sub ProcessWindowMessage(ByRef m As System.Windows.Forms.Message)
If m.Msg = _MsgID_CallWndProc Then
_CacheHandle = m.WParam
_CacheMessage = m.LParam
ElseIf m.Msg = _MsgID_CallWndProc_Params Then
If CallWndProc IsNot Nothing AndAlso _CacheHandle <> IntPtr.Zero AndAlso _CacheMessage or CallWndProc IsNot Nothing AndAlso _CacheHandle <> IntPtr.Zero Then
CallWndProc(_CacheHandle, _CacheMessage, m.WParam, m.LParam)
End If
_CacheHandle = IntPtr.Zero
_CacheMessage = IntPtr.Zero
ElseIf m.Msg = _MsgID_CallWndProc_HookReplaced Then
RaiseEvent HookReplaced()
End If
End Sub
if (CallWndProc != null)
{
}
VB.NET
If Not IsNothing(CallWndProc) Then
End If --------------------编程问答-------------------- 网上不是很多网站都能把VB.NET和C#代码相互转化的吗???????????????????????????????????????????????????????????????????? --------------------编程问答-------------------- '//Convert to vb.net code
Public Delegate Sub WndProcEventHandler(ByVal Handle As IntPtr, ByVal Message As IntPtr, ByVal wParam As IntPtr, ByVal lParam As IntPtr)
Public Event CallWndProc As WndProcEventHandler
Public Overloads Overrides Sub ProcessWindowMessage(ByRef m As System.Windows.Forms.Message)
If m.Msg = _MsgID_CallWndProc Then
_CacheHandle = m.WParam
_CacheMessage = m.LParam
ElseIf m.Msg = _MsgID_CallWndProc_Params Then
If CallWndProc IsNot Nothing AndAlso _CacheHandle <> IntPtr.Zero AndAlso _CacheMessage <> IntPtr.Zero Then
CallWndProc(_CacheHandle, _CacheMessage, m.WParam, m.LParam)
End If
_CacheHandle = IntPtr.Zero
_CacheMessage = IntPtr.Zero
ElseIf m.Msg = _MsgID_CallWndProc_HookReplaced Then
RaiseEvent HookReplaced()
End If
End Sub
补充:.NET技术 , VB.NET