using System.Runtime.InteropServices;
[DllImport("gdi32.dll")] 
private static extern int GetPixel (IntPtr hdc , int x1,int y1);[DllImport("gdi32.dll")] 
    private static extern int SetPixel (IntPtr hdc , int x1,int y1,int color);

解决方案 »

  1.   

    参见如下简单例子:
    // Copyright
    // Microsoft Corporation
    // All rights reserved// MsgBox.csusing System;
    using System.Runtime.InteropServices;public class LibWrap 
    {
    // int MessageBox(HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType);

    [ DllImport( "User32.dll", EntryPoint="MessageBox", CharSet=CharSet.Auto )]
    public static extern int MsgBox( int hWnd, String text, String caption, uint type );

    // this will cause incorrect output in message window

    [ DllImport( "User32.dll", EntryPoint="MessageBoxW", CharSet=CharSet.Ansi )]
    public static extern int MsgBox2( int hWnd, String text, String caption, uint type );

    // this will cause an exception

    [ DllImport( "User32.dll", EntryPoint="MessageBox", CharSet=CharSet.Ansi, ExactSpelling=true )]
    public static extern int MsgBox3( int hWnd, String text, String caption, uint type );
    }public class MsgBoxSample
    {
    public static void Main()
    {
    LibWrap.MsgBox( 0, "Correct text", "MsgBox Sample", 0 );
    LibWrap.MsgBox2( 0, "Incorrect text", "MsgBox Sample", 0 );
    try
    {
    LibWrap.MsgBox3( 0, "No such function", "MsgBox Sample", 0 );
    }
    catch( EntryPointNotFoundException )
    {
    Console.WriteLine( "EntryPointNotFoundException thrown as expected!" );
    }
    } private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
    {
    DialogResult r = MessageBox.Show ( "是否关闭窗口!" , "关闭窗口!" , MessageBoxButtons.YesNo , MessageBoxIcon.Question ) ;
    if (!(DialogResult.Yes ==r))
    {
    e.Cancel = true;
    }
    }
    }
      

  2.   

    download api explorer help ufrom: http://zpcity.com/arli
      

  3.   

    ms-help://MS.VSCC/MS.MSDNVS.2052/vblr7/html/vastmDeclare.htm
    ms-help://MS.VSCC/MS.MSDNVS.2052/vbcn7/html/vaconCallingWindowsAPIs.htm
      

  4.   

    方法各位都说了,我只想提醒一下,请注意数据类型的对应关系,因为你看api的函数声明一般都是基于VB或VC的,一般如下:
    如果是字符串指针,在C#中用StringBuilder,用BYTE[]也行;
    如果是int或long用int,是指针的话加一个ref或out;
    其它的我也不多说了,只要注意到这点后,上网可以找些东东看看,还有是结构也要注意一下。