level 8
fjy206
楼主
Private Declare Function GetLastInputInfo Lib "user32" (ByRef plii As IntPtr) As Long '把结构 重新定义为 指针 IntPtr
Private Declare Function GetTickCount Lib "kernel32" () As Long
''' <summary>
''' 结构体声明
''' </summary>
<Runtime.InteropServices.StructLayout(Runtime.InteropServices.LayoutKind.Sequential)>
Public Structure LASTINPUTINFO
<MarshalAsAttribute(UnmanagedType.U4)>
Dim cbSize As UInt32
<MarshalAsAttribute(UnmanagedType.U4)>
Dim dwTime As Int32 End Structure Private Function aa() As Integer Dim lastInputInfo As New LASTINPUTINFO lastInputInfo.cbSize = Marshal.SizeOf(lastInputInfo) Dim thObject2 As Runtime.InteropServices.GCHandle = Runtime.InteropServices.GCHandle.Alloc(lastInputInfo, Runtime.InteropServices.GCHandleType.Pinned)
Dim tpObject2 As IntPtr = thObject2.AddrOfPinnedObject() '取得指向结构的指针
Dim f As Integer Try Dim lostTime As String = "" Dim ret As Long = GetLastInputInfo(tpObject2) If ret <> 0 Then f = lastInputInfo.dwTime 'f = lostTime'/ 1000 / 60 ' MsgBox(lostTime / 1000 / 60) End If Catch ex As Exception MsgBox(ex.ToString) End Try '在使用完毕后一定要释放指针指向的内存块,让垃圾回收器可对这个内存块回收处理
If thObject2.IsAllocated Then thObject2.Free() End If
Return f
End Function
2017年12月29日 01点12分
1
Private Declare Function GetTickCount Lib "kernel32" () As Long
''' <summary>
''' 结构体声明
''' </summary>
<Runtime.InteropServices.StructLayout(Runtime.InteropServices.LayoutKind.Sequential)>
Public Structure LASTINPUTINFO
<MarshalAsAttribute(UnmanagedType.U4)>
Dim cbSize As UInt32
<MarshalAsAttribute(UnmanagedType.U4)>
Dim dwTime As Int32 End Structure Private Function aa() As Integer Dim lastInputInfo As New LASTINPUTINFO lastInputInfo.cbSize = Marshal.SizeOf(lastInputInfo) Dim thObject2 As Runtime.InteropServices.GCHandle = Runtime.InteropServices.GCHandle.Alloc(lastInputInfo, Runtime.InteropServices.GCHandleType.Pinned)
Dim tpObject2 As IntPtr = thObject2.AddrOfPinnedObject() '取得指向结构的指针
Dim f As Integer Try Dim lostTime As String = "" Dim ret As Long = GetLastInputInfo(tpObject2) If ret <> 0 Then f = lastInputInfo.dwTime 'f = lostTime'/ 1000 / 60 ' MsgBox(lostTime / 1000 / 60) End If Catch ex As Exception MsgBox(ex.ToString) End Try '在使用完毕后一定要释放指针指向的内存块,让垃圾回收器可对这个内存块回收处理
If thObject2.IsAllocated Then thObject2.Free() End If
Return f
End Function