C#调用win32 api程序实例

1、声明static extern 方法,使用DllImport特性

   class MyClass
    {
        [DllImport("kernel32", SetLastError = true)]
        public static extern int GetCurrentDirectory(int a, StringBuilder b);
    }

2、调用

StringBuilder sb=new StringBuilder {Length = 250};
MyClass.GetCurrentDirectory(250, sb);
Console.WriteLine(sb);
Console.Read();

posted @ 2015-10-25 14:59  瓜王  阅读(522)  评论(0编辑  收藏  举报