日期:2014-05-20  浏览次数:20893 次

谁能给我个C#调用API的例子
最近在学习C#里调用API,但网上文章太简洁了,而且都是MSDN上的话,看了后对于这初学者不太明白,哪位能做个简单的C#调用API的实例让我参考下?谢谢!

------解决方案--------------------
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential)]
public class SystemTime
{
public ushort year;
public ushort month;
public ushort dayOfWeek;
public ushort day;
public ushort hour;
public ushort minute;
public ushort second;
public ushort milliseconds;
}
[DllImport( "Kernel32.dll ")]
public static extern void GetSystemTime([In, Out] SystemTime st);

[DllImport( "Kernel32.dll ")]
public static extern bool SetSystemTime([In, Out] SystemTime st);

SystemTime vSystemTime = new SystemTime();
GetSystemTime(vSystemTime);
vSystemTime.year += 1;
SetSystemTime(vSystemTime);