2010-07-05 94 views
1

我是vb.net(框架4)的新手,Visual Studio在以下聲明中給我提出了警告。vb.net聲明的問題

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) 

更重要的是我如何在未來找出正確的聲明?

+1

http://pinvoke.net/是一個很好的資源,但它通常只有C# – Rup 2010-07-05 18:13:12

+0

當你提到一些錯誤或警告,請將它們添加到你的問題 – Andrey 2010-07-05 18:15:17

回答

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纔是。

3

它看起來像你正在轉換一個VB6應用程序。所有這些函數都有.net等價物,使用它們。

+0

我不是故意粗魯,但我在哪裏可以找到這種等同物? – Jigs 2010-07-05 18:22:05

+0

爲睡眠功能使用 System.Threading.Thread.Sleep(no_of_milliseconds) 如果您創建一個窗體大多數其他功能是窗體的屬性 – David 2010-07-05 19:05:45