C#怎么调用VC中可以用的api,如调用函数GetLastInputInfo,GetTickCount等

.Net技术 码拜 8年前 (2016-02-29) 922次浏览
如题,下面这段代码在VC中可直接用,那么在C#中该怎么调用

LASTINPUTINFO lpi;
	lpi.cbSize = sizeof(lpi);
	GetLastInputInfo(&lpi);//获取上次输入操作的时间。
	DWORD dwTickCount = ::GetTickCount();
	if ((::GetTickCount()-lpi.dwTime)>1000*60)//1分钟
	{
		MessageBox("已闲置超过1分钟!");
	}
解决方案

20

在vs2008的工具菜单中有一个”win32 api tool”, 可以查看大部分 windows api 和结构体在 vb 和 c# 中的使用语法.

[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public struct tagLASTINPUTINFO {
    /// UINT->unsigned int
    public uint cbSize;
    /// DWORD->unsigned int
    public uint dwTime;
}
public partial class NativeMethods {
    /// Return Type: BOOL->int
    ///plii: PLASTINPUTINFO->tagLASTINPUTINFO*
    [System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint="GetLastInputInfo")]
    [return: System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)]
public static extern  bool GetLastInputInfo([System.Runtime.InteropServices.OutAttribute()] out tagLASTINPUTINFO plii) ;
}

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明C#怎么调用VC中可以用的api,如调用函数GetLastInputInfo,GetTickCount等
喜欢 (1)
[1034331897@qq.com]
分享 (0)