本帖最后由 caitlin_yu 于 2010-11-11 15:15:48 编辑

解决方案 »

  1.   

    声明:本人C语言不太好,以下建议不保证完全正确首先引用该dll,[DllImport("kernel32.dll")]
    调用代码:
    double number=kernel32.durationCompute(参数1(类型:short int),参数2(类型:int));
      

  2.   

    [DllImport("你的dll", CallingConvention = CallingConvention.StdCall)]
    public static unsafe extern float durationCompute(short** frameMat,int frameCount);
    不是很懂,大概是这样
      

  3.   

    [DllImport("你的dll", CallingConvention = CallingConvention.StdCall)]
    public static unsafe extern float durationCompute(IntPtr frameMat,int frameCount);
      

  4.   

    以前研究过一下,不过也怎么清楚,这是我的代码,也许能帮上你
    1:打开vs2008,新建一个类库,名为Cmdll(C++.net语言)
    2:在Cmdll.h中输入以下代码:
    extern "C" __declspec(dllexport) int SampleMethod(int i)
    {
       return i*10;
    }3:编译一下,在项目的文件夹里会生成Cmdll.dll文件。这个就可以在c#中调用了。
    c#调用如下
    using System;
    using System.Runtime.InteropServices;
    namespace ConsoleApplication1
    {
        class Program
        {
            [DllImport("Cmdll.dll", EntryPoint = "SampleMethod")]
            public static extern int SampleMethod(int x);
            static void Main(string[] args)
            {
                Console.WriteLine("SampleMethod() returns {0}.", SampleMethod(5));
                Console.Read();
            }
        }
    }
      

  5.   

    extern "C" __declspec(dllexport) 
    的位置好像不能变。也记不清了,楼主你自己试试吧。
    别忘了把Cmdll.dll文件拷到c#的项目文件夹bin里,至于用不用添加引用就计不清了,你自己试试吧
      

  6.   

    [DllImport("Cmdll.dll", EntryPoint = "SampleMethod")]
      public static extern int SampleMethod(int x);
    这个是你在c#里的函数名字,你直接调用就相当于调用c的函数了吗。用一个对应类型的变量接收不就得了
      

  7.   

    你把API原函数贴出来吧。
    参考:http://www.cnblogs.com/yufb/archive/2010/06/02/1749837.html看看参数转换
      

  8.   

    楼主可参考这个SDK,里面有C#调用C++写的DLL的源代码,实现了一个简单的语音、视频通话的平台,估计有用:http://www.anychat.cn/faq/,在SDK包的:src\client\c#目录下。
      

  9.   


    大哥里面有好多SDK,你指的是哪个?
      

  10.   


    C#引用导出函数的参数,我还是引不出来,是不是到处方法不对?那参数要怎么导出,我这**frameMat是双指针呀,怎么整啊~~大虾帮帮忙吧
      

  11.   

    百度一下调用win32使用
    ok.
      

  12.   

    如果是一个标准的C导出Dll,那么需要用DllImport导入函数,参考互操作内容实际调用类似于这样的代码 public class MPwdMngAPI
      {
      [DllImport("PwdMng.dll", CharSet = CharSet.Ansi, EntryPoint = "SetUserFirstLogin")]
      public extern static bool ResetUserToFirstUse(String username);  [DllImport("PwdMng.dll", CharSet = CharSet.Ansi, EntryPoint = "ChangePassword")]
      public extern static int ChangePassword(String userName, String oldPwd, String newPwd); 
    }要单独写个类 
    把那个DLL添加在Dbug里
    打包的时候也别忘了
      

  13.   


    我编程菜鸟一个
    dll里有这样一个导出函数,
    int volumeLevel(signed short **frameMat,const int frameCount)//能量等级检测
    {
    int i;
    int averageVol=0;
    //用于保存能量向量
    int *volume=(int*)malloc(frameCount*sizeof(int));
    volumeCompute(frameMat,volume,frameCount);
    for(i=0;i<frameCount;i++)
    averageVol += volume[i];
    averageVol /= frameCount;
    if(averageVol > 6000000)
    return 3;
    else if(averageVol > 500000)
    return 2;
    else if(averageVol > 50000)
    return 1;
    else 
    return 0;
    }
    在C#中我怎样得到返回值呢?frameMat, frameCount这两个参数要怎么弄呢??拜托高人指点~~
      

  14.   

        [System.Runtime.InteropServices.DllImportAttribute("你的DLL", EntryPoint="durationCompute")]
    public static extern  float durationCompute(ref System.IntPtr frameMat, int frameCount) ;
    不知道对不对了