通过调用user32.dll 来实现键盘鼠标无操作锁屏,但执行到Call GetLastInputInfo(IOInfo) 就报“尝试读取或写入受保护的内存。这通常指示其他内存已损坏。”百思不得其解,请大家帮忙,感谢!!!
vb.net 代码如下
Private Declare Function GetLastInputInfo Lib "user32" (ByVal plii As LASTINPUTINFO) As Boolean
Dim IOInfo As LASTINPUTINFO
Dim LngBak As Long
Dim LngCnt As Long
Dim LngEnd As Long
Private Structure LASTINPUTINFO
Dim cbSize As Int32
Dim dwTime As Int32
End Structure
Private Sub jyfx_main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
LngEnd = 100
LngCnt = 0
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
IOInfo.cbSize = Len(IOInfo)
Call GetLastInputInfo(IOInfo)
If LngBak <> IOInfo.dwTime Then
LngBak = IOInfo.dwTime
LngCnt = 0
End If
LngCnt = LngCnt + 1
If LngCnt = LngEnd Then
Timer1.Enabled = False
MsgBox("系统锁定中!", MsgBoxStyle.Information, "经营管理分析系统")
Timer1.Enabled = True
End If
End Sub
------解决思路----------------------
你的api声明是vb6的,你可以在pinvoke.net这个网站找vb.net版的。