• λ我爱Aspx >> C#.Net >> 用Visual C#调用Windows API函数
  • 用Visual C#调用Windows API函数

  • :aspxer  Դ:internet  :2007-5-7 13:28:26  ؼ:c#
  • [DllImport("User32.dll")]

    public static extern Bool PtInRect(ref Rect r, Point p);

    }

    类似你可以调用GetSystemInfo函数获得系统信息:

    ? using System.Runtime.InteropServices;

    [StructLayout(LayoutKind.Sequential)]

    public struct SYSTEM_INFO {

    public uint dwOemId;

    public uint dwPageSize;

    public uint lpMinimumApplicationAddress;

    public uint lpMaximumApplicationAddress;

    public uint dwActiveProcessorMask;

    public uint dwNumberOfProcessors;

    public uint dwProcessorType;

    public uint dwAllocationGranularity;

    public uint dwProcessorLevel;

    public uint dwProcessorRevision;

    }

    [DllImport("kernel32")]

    static extern void GetSystemInfo(ref SYSTEM_INFO pSI);

    SYSTEM_INFO pSI = new SYSTEM_INFO();

    GetSystemInfo(ref pSI);

    类成员的传递

    同样只要类具有一个固定的类成员布局,你也可以传递一个类成员给一个不受管辖的动态链接库函数,下面的例子主要说明如何传递一个sequential顺序定义的MySystemTime类给User32.dll的GetSystemTime函数, 函数用C/C++调用规范如下:

    void GetSystemTime(SYSTEMTIME* SystemTime);

    不像传值类型,类总是通过引用传递参数.

    [C#]

    [StructLayout(LayoutKind.Sequential)]

    public class MySystemTime {

    public ushort wYear;

    public ushort wMonth;

    public ushort wDayOfWeek;

    public ushort wDay;

    public ushort wHour;

    public ushort wMinute;

    public ushort wSecond;

    public ushort wMilliseconds;

    }

    class Win32API {

    Ҷƪл˵?
  • һƪC#写的ADSL拨号程序示例
    һƪ编写C#程序实现动态系统托盘图标