请教:C#程序中需要得到外部函数的值,
函数:
long a(void * S,void ** V)
S:源数据,V:为处理后的数据,返回为处理后数据长度
在C#中怎样得到V值.

解决方案 »

  1.   

    是函数指针还是对象/结构体的指针?
    如果是后者则可以用Marshal.PtrToStructure方法如果是函数指针则比较麻烦了,.NET 2.0可以用Marshal.GetDelegateForFunctionPointer实现
    现在要做这个比较麻烦,codeproject上有人用Win32汇编写了个例子
      

  2.   

    我传入函数的S和V都需是byte[] 类型
      

  3.   

    IntPtr v;
    IntPtr pv;
    YourStruct obj;
    Marshal.PtrToStructure(v, pv);
    Marshal.PtrToStructure(pv, obj);
      

  4.   

    对象指针就用Marshal.PtrToStructure即可,函数指针是堆上的,不好获得。
      

  5.   

    使用c#的unsafe 方式
    byte *BB=null;
    byte[] AA;
    int cc;
    cc=a(ref AA[0],&BB);byte[] DD=new byte[DataBufL];
    for(int U=0;U<cc;U++)
    {
       DD[U]=*(BB+U);
    }得到处理完的数组 DD
    问题解决
      

  6.   

    C#对内存操作的功能太弱,在C++中是堆的概念,这也是C++比C#强大的原因之一