我是vb.net(框架4)的新手,而visual studio正在向我发出以下声明的警告。
Private Declare Auto Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Private Declare Auto Function FindWindow Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Private Declare Auto Function GetWindowText Lib "user32" (ByVal hwnd As IntPtr, ByVal lpString As String, ByVal cch As IntPtr) As IntPtr
Private Declare Auto Function keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Integer, ByVal dwExtraInfo As Integer) As Boolean
Private Declare Auto Function SendMessage Lib "user32" (ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
Private Declare Auto Function SetForegroundWindow Lib "user32" (ByVal hWnd As IntPtr) As Boolean
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Integer)
更重要的是,如何在将来找到正确的声明?
答案 0 :(得分:3)
看起来您正在转换vb6应用。所有这些功能都有.net Equivalents,使用它们。
答案 1 :(得分:2)
我无法想象你会从这些声明中得到警告。但是,是的,EnumChildWindows是错误的,不可能在VB.NET程序中使用。修正:
Private Delegate Function EnumChildCallback(ByVal hWnd As IntPtr, ByVal lparam As IntPtr) As Boolean
Private Declare Auto Function EnumChildWindows Lib "user32" (ByVal hWndParent As IntPtr, ByVal lpEnumFunc As EnumChildCallback, ByVal lParam As IntPtr) As Boolean
GetWindowText的cch参数错误,它是Integer。其余的都很好。
Pinvoke.net是这些声明的合理合适资源。或者您可以使用P/Invoke Interop Assistant工具。它们都不是完美的,只有SO才是。