一样的东西DllImportAttribute是这个特性的类[DllImport]是这特性的描述。

解决方案 »

  1.   

    DllImport = DllImportAttribute,Attribute在使用时可以省略不写
      

  2.   

    我觉得DllImport是关键字,而引入DLL需要写明其它属性,例如如下所示,DllImport后面括号中间都是DllImportAttribute
    [DllImport("KERNEL32.DLL", EntryPoint="MoveFileW",  SetLastError=true,
    CharSet=CharSet.Unicode, ExactSpelling=true,
    CallingConvention=CallingConvention.StdCall)]
    public static extern bool MoveFile(String src, String dst);
      

  3.   

    以下是我在书上看见的一段代码,如果两者相同,为何作者要在同一段代码中应用两种不同的编程风格?都用DllImport不是简单多呢?
    [DllImport("gdi32.dll")]
    private static extern bool BitBlt(
    IntPtr hdcDest, // hanlde to destination Dc (device context)
    int nXDest,  // x-coord of destination upper-left corner
    int nYDest,  // y-coord of destination upper-left corner
    int nWidth,  // width of destination rectangle
    int nHeight, // height of destination rectangle
    HDC hdcSrc,  // handle to source DC
    int nXSrc,   // x-coordinate of source upper-left corner
    int nYSrc,   // y-coordinate of source upper-left corner
    System.Int32 dwRop  // raster operation code
    ); [DllImport("gdi32.dll")]
    private static extern IntPtr CreateDC(
    String DriverName,    // driver name
    String DeviceName,     // device name
    String Output,    // not used; should be NULL
    IntPtr lpInitData    // optional printer data
    ); [System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
    private static extern bool DeleteDC(
    IntPtr dc
    ); [System.Runtime.InteropServices.DllImportAttribute("user32.dll")]
    private static extern unsafe bool ClientToScreen(
    IntPtr hWnd,    // handle to window
    Point* lpPoint  // screen coordinates
    );