有点抓狂了 
说明里写的是 void far * 可是它例子里又是 unsigned char 
我试过用 string  char[]  stringbuilder 好像都不行 IntPtr  我也尝试用了下 好像也不行..有没人帮忙指点指点.

解决方案 »

  1.   

    [DllImport("IBFS32.dll")]
            public static extern int TMNext(long session_handle, int state_buffer);
     
            [DllImport("IBFS32.dll")]
            public static extern int TMRom(long session_handle, int state_buffer, int ROM);
     
    两个函数这么定义的,用的时候使用IntPtr.ToInt32()就可以
      

  2.   

    抱歉代码有问题,没注意是var far.,那就应该换成int64
    这个样子:[DllImport("IBFS32.dll")]
            public static extern int TMNext(long session_handle, long state_buffer);
      
            [DllImport("IBFS32.dll")]
            public static extern int TMRom(long session_handle, long state_buffer, long ROM);
      用的时候使用IntPtr.ToInt64()就可以
      

  3.   

    露珠那段C++代码翻译成C#大致是这样        [DllImport("IBFS32.dll")]
            public static extern int TMNext(long session_handle, long state_buffer);        [DllImport("IBFS32.dll")]
            public static extern int TMRom(long session_handle, long state_buffer, long ROM);
             static void Main(string[] args)
            {
                long SHandle=0;
                byte[] state_buf = new byte[5125];
                byte[] ROM = new byte[9];
                IntPtr state_bufptr = GCHandle.Alloc(state_buf).AddrOfPinnedObject();
                IntPtr ROMptr = GCHandle.Alloc(ROM).AddrOfPinnedObject();
                //flag = TMNext(SHandle,(void far *)&state_buf[0]);
                int flag=TMNext(SHandle,state_bufptr.ToInt64());
                if (flag > 0)
                {
                    ROM[0] = 0;
                    //flag = TMRom(SHandle,(void far *)&state_buf[0],(short far *)&ROM[0]);
                    flag = TMRom(SHandle, state_bufptr.ToInt64(), ROMptr.ToInt64());
                    for (int i = 7; i >= 0; i--)
                    {
                        Console.Write("{0}",ROM[i]);
                    }
                    Console.WriteLine();
                }
            }
      

  4.   


    非常感谢您            IntPtr state_bufptr = GCHandle.Alloc(state_buf).AddrOfPinnedObject();
    这句话  会抛出个句柄未被固定的异常
      

  5.   

    抱歉昨天随手就写了些代码没有测试.今天写完了测试了下,正确写法应该如下
    千万注意被GCHandle管理的内存不会自动释放,所以用完了一定要调用free显示释放内存,否则可能会导致内存泄漏
            [DllImport("IBFS32.dll", CallingConvention = CallingConvention.StdCall)]
            public static extern int TMNext(int session_handle, int state_buffer);        [DllImport("IBFS32.dll", CallingConvention = CallingConvention.StdCall)]
            public static extern int TMRom(int session_handle, int state_buffer, int ROM);
      
            static void Main(string[] args)
            {
                int SHandle = 0;
                byte[] state_buf = new byte[5125];
                byte[] ROM = new byte[9];
                GCHandle state_buf_handle = GCHandle.Alloc(state_buf, GCHandleType.Pinned);
                GCHandle ROM_handle = GCHandle.Alloc(ROM, GCHandleType.Pinned);            IntPtr state_bufptr = state_buf_handle.AddrOfPinnedObject();
                IntPtr ROMptr = ROM_handle.AddrOfPinnedObject();
                //flag = TMNext(SHandle,(void far *)&state_buf[0]);
                int flag = TMNext(SHandle, state_bufptr.ToInt32());
                if (flag > 0)
                {
                    ROM[0] = 0;
                    //flag = TMRom(SHandle,(void far *)&state_buf[0],(short far *)&ROM[0]);
                    flag = TMRom(SHandle, state_bufptr.ToInt32(), ROMptr.ToInt32());
                    for (int i = 7; i >= 0; i--)
                    {
                        Console.Write("{0}",ROM[i]);
                    }
                    Console.WriteLine();
                }
                state_buf_handle.Free();
                ROM_handle.Free();
            }
      

  6.   

    byte[] ROM = new byte[9];
    这个应该声明成
    short[] ROM=new short[9];
    CSDN不能改答案真捉急答完了,出去玩去了