- 写了一个鼠标锁程序,但是ClipCursor函数的.net下调用却出了点问题。以下是代码,调试时出现
- [quote]对 PInvoke 函数“鼠标锁!鼠标锁.Form1::ClipCursor”的调用导致堆栈不对称。原因可能是托管的 PInvoke 签名与非托管的目标签名不匹配。请检查 PInvoke 签名的调用约定和参数与非托管的目标签名是否匹配。[/quote]
- 查找了MSDN中API函数在.net上运行发现,在VB6中的数据类型long在VB2005中要变成integer,我改过来,但是仍然出现错误。先在这里描述一下问题,等待解决问题的时候,会将结果写出来。
- Public Class Form1
- Public Structure RECT
- Dim Left As Integer
- Dim Top As Integer
- Dim Right As Integer
- Dim Bottom As Integer
- End Structure
- Public Declare Function ClipCursor Lib “user32” (ByVal lpRect As RECT) As Integer
- Public Sub lockMouse()
- Dim lockRECT As RECT
- lockRECT.Left = 0
- lockRECT.Top = 0
- lockRECT.Right = 0
- lockRECT.Bottom = 0
- ClipCursor(lockRECT)
- End Sub
- Public Sub openMouse()
- Dim openRECT As RECT
- openRECT.Left = 0
- openRECT.Top = 0
- openRECT.Right = Me.Width
- openRECT.Bottom = Me.Height
- ClipCursor(openRECT)
- End Sub
- Private Sub btnLock_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLock.Click
- lockMouse()
- End Sub
- Public password As String
- Private Sub btnSetPassword_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetPassword.Click
- Try
- password = InputBox(“请输入你的密码:”)
- Catch ex As Exception
- MsgBox(“请输入正确有效的密码”, MsgBoxStyle.OkOnly)
- End Try
- End Sub
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- End Sub
- Private Sub btnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpen.Click
- Dim OpenPassword As String
- Try
- OpenPassword = InputBox(“请输入密码:”)
- If OpenPassword = password Then
- openMouse()
- Else
- MsgBox(“密码错误”)
- End If
- Catch ex As Exception
- MsgBox(ex.Message)
- End Try
- End Sub
- End Class
出现错误的原因出于声明变量的方式上。
之前是用byval按值传递,因为它传递的是数值,如果每次按值传递的话,原函数是指针传递,就会出现参数类型不符,所以应该用Byref.
今天的文章ClipCursor函数引用注意分享到此就结束了,感谢您的阅读。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/6745.html