GetLastInputInfo
От: Аноним  
Дата: 29.11.09 13:06
Оценка:
здравствуйте господа !

Я пытаюсь применить функцию WinApi GetLastInputInfo(LASTINPUTINFO plii)
и как показано ниже вызываю ее с проверкой на true и false
if (GetLastInputInfo(linput))
Компилится все нормально .
Однако когда я пытаюсь выполнить это выдается сообщение System.AccessViolationException was unhandled
которое описано ниже .
Может быть ктото уже на эти грабли наступал ?
И как вообще тогда правильно применить GetLastInputInfo для простого обнаружения активности пользователя ?


[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
internal static extern bool GetLastInputInfo(LASTINPUTINFO plii);
internal struct LASTINPUTINFO
{
internal long cbSize;
internal long dwTime;
}


LASTINPUTINFO linput;

if (GetLastInputInfo(linput))


System.AccessViolationException was unhandled
Message="Попытка чтения или записи в защищенную память. Это часто свидетельствует о том, что другая память повреждена."
Source="Power"
StackTrace:
в Power.Form1.GetLastInputInfo(LASTINPUTINFO plii)
в Power.Form1.timer1_Tick(Object sender, EventArgs e) в C:\Developer_project\C#\Power\Power\Form1.cs:строка 62
в System.Windows.Forms.Timer.OnTick(EventArgs e)
в System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
в System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
в System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
в System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
в System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
в System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
в System.Windows.Forms.Application.Run(Form mainForm)
в Power.Program.Main() в C:\Developer_project\C#\Power\Power\Program.cs:строка 19
в System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
в System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
в Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
в System.Threading.ThreadHelper.ThreadStart_Context(Object state)
в System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
в System.Threading.ThreadHelper.ThreadStart()
InnerException:


03.12.09 08:54: Перенесено модератором из '.NET' — TK
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.