如题。请简单给个例子。

解决方案 »

  1.   

    可以
    看了这个例子,你应该会了,这样声明一下就可以用了
    [DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
    public static extern IntPtr GetWindowDC(IntPtr hwnd);
      

  2.   

    C:
    #include   "StdAfx.h"  
    #include   "Dll.h"  
     
    extern   "C"   __declspec(dllexport)   int   fun(int   x1,int   x2,int   x3)   
    {   
    return x1+x2+x3;
    }
    编译成 CDLL6.dll 
    C#public class Win32API
        {
            /// <summary>
            /// 
            /// </summary>
            /// <param name="ncb"></param>
            /// <returns></returns>
            [DllImport("CDLL6.dll")]
            public static extern int fun(int x1, int x2, int x3);
        }
    调用:int j = Win32API.fun(1,2,3);
      

  3.   

    为什么老是提示我,无效的表达式项"]";
    [DllImport("CDLL6.dll")]引用的时候为什么有错误?