高分请教api的getwindow问题

来源:百度知道 编辑:UC知道 时间:2024/06/03 23:29:58
Public Class Form1

Public Declare Function FindWindow Lib "USER32.DLL" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function GetForegroundWindow Lib "user32" () As Long

Dim Titlelen As Long
Dim Resule As Long
Dim Title As String
Dim x As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Resule = GetForegroundWindow()

GetWindowText(Resule, Title, Titlelen)

x = Title
TextBox1.Text = x
If Resule Then
Label1.Text = Resule
End If
End Sub
End Class

这就是我的程序 编译通过 但是当运行到GetWindowText(Resule, Title, Titlelen)时出错

显示一个框 <

将debug里的exception中的manager debug 。。。。。全去掉

原因
平台调用的托管签名可能与要调用的方法的非托管签名不匹配。这种不匹配情况可能是由以下原因造成的:托管签名声明的参数数量不正确或指定的参数大小不合适。调用约定(可能由 DllImportAttribute 属性指定)与非托管调用约定不匹配。

解决办法
检查托管平台调用签名和调用约定,以确认其与本机目标的签名和调用约定相匹配。尝试在托管端和非托管端都显示指定调用约定。虽然可能性不大,但也有可能是非托管函数由于其他某种原因(如非托管编译器中的 bug)使堆栈失去了平衡。

VB.NET....可惜我是已经是C#的人了...要是有问题再说吧

user32改为user32.dll