如 调用  xxx.dll,
dll中定义了 int f1(),  int f2()...等函数。如何调用dll中的函数?请大家多多指教。谢谢。。

解决方案 »

  1.   

    看C# 的DllImport怎么用 就知道了
      

  2.   

    通过反射调用,例子:
    http://msdn.microsoft.com/zh-cn/library/ms173183(VS.80).aspx
      

  3.   

    dll 是谁写的区别很大,托管的直接用就行了,非拖管的要用DllImport还要考虑stdcall,类型转换等问题
      

  4.   


    看了DllImport,也没弄清楚。才来问问。
      

  5.   

    例如
            [DllImport("test.dll")]
            public static extern int f1();
      

  6.   


    [DllImport("xxx.dll")]
    public static extern int f1();
    [DllImport("xxx.dll")]
    public static extern int f2();之後直接用 f1() 或 f2() 呼叫就可以了,如果不行,一定是你 C++ 有寫錯,例如沒有導出。
      

  7.   


    那 "xxx.dll"应该放在什么路径下?     
    直接写[DllImport("xxx.dll")],提示:unable to load dll ,找不到指定模块
      

  8.   

    你把xxx.dll放在你的Bin目录下试试。
      

  9.   

    额。。 说错了,是放在bin\Debug目录下。。
      

  10.   

    给你个例子:/// <summary>
            /// 停止当前任务
            /// </summary>
            /// <returns></returns>
            [DllImportAttribute("AudioEditor.dll", EntryPoint = "AEStop", CallingConvention = CallingConvention.StdCall)]
            public static extern int AEStop();EntryPoint: 指定要调用的 DLL 入口点。默认入口点名称是托管方法的名称 。 
    CallingConvention指示入口点的函数调用约定(默认WINAPI)
      

  11.   

    xxx.dll 放在你要執行的 exe 檔同一個路徑下,如果你建置是以 Debug 的話,就放在 Bin\Debug 下,如果建置是以 Release 就放在 Bin\Release 下。