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

解决方案 »

  1.   

    先定义
    [DllImport("kernel32")]
            private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
       
    后使用
     WritePrivateProfileString("", "", textBox1.Text.Trim(), ".\\config.ini");
      

  2.   

    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);
      

  3.   

    我学习C#震得很迷茫,树上都是讲的基础东西,没有提到api调用,msdn又说得不全面,大家的这些知识又是从哪学到的呢?
      

  4.   

    去这里查,函数定义和例子都有
    http://pinvoke.net/