【发布时间】:2013-02-06 15:26:33
【问题描述】:
我已经声明了以下 WinAPI 调用
<DllImport("USER32.DLL", EntryPoint:="GetActiveWindow", SetLastError:=True,
CharSet:=CharSet.Unicode, ExactSpelling:=True,
CallingConvention:=CallingConvention.StdCall)>
Public Shared Function GetActiveWindowHandle() As System.IntPtr
End Function
<DllImport("USER32.DLL", EntryPoint:="GetWindowText", SetLastError:=True,
CharSet:=CharSet.Unicode, ExactSpelling:=True,
CallingConvention:=CallingConvention.StdCall)>
Public Shared Function GetActiveWindowText(ByVal hWnd As System.IntPtr, _
ByVal lpString As System.Text.StringBuilder, _
ByVal cch As Integer) As Integer
End Function
然后,我调用这个子程序来获取活动窗口标题栏中的文本
Public Sub Test()
Dim caption As New System.Text.StringBuilder(256)
Dim hWnd As IntPtr = GetActiveWindowHandle()
GetActiveWindowText(hWnd, caption, caption.Capacity)
MsgBox(caption.ToString)
End Sub
最后,我收到以下错误
无法在 DLL 中找到名为“GetWindowText”的入口点 'USER32.DLL'
我该如何解决这个问题?
【问题讨论】:
-
尝试改变 CharSet:=CharSet.Auto
-
this 为我工作。
标签: vb.net winforms winapi dllimport user32