c#如何调用C语言写的函数,给详细代码,谢谢

解决方案 »

  1.   

    [DllImport("smgwapi.dll", EntryPoint = "CNGPActiveTest")]
            public static extern int AcitveTest(out int nErrorCode);关于数据类型的描述参考:
    http://18la.cn/blog/post/77.html
      

  2.   

    c函数编译成dll,然后pinvoke就可以了。比如一个
    BOOL DrawIcon(
      HDC hDC, 
      int X, 
      int Y, 
      HICON hIcon
    ); c#文件中声明这个外部函数,就可以直接在程序里调用了
    [DllImport("user32.dll")]
    static extern bool DrawIcon(IntPtr hDC, int X, int Y, IntPtr hIcon);
    public void MyFunc()
    {
        bool result = DrawIcon(..., ..., ..., ...);
    }
    更多内容参考http://www.pinvoke.net/