现在C#中引用Delphi中dll里的方法,其它方法都是没问题的,唯独这个,老是出问题:
SetClockModeEx: 设置设备工作模式
 语法:
   function SetClockModeEx(hPort: THandle; Mode: Integer; ExtraMode: Integer; 
     SystemMode: Integer; RingMode: Integer): Boolean; 参数说明:
   hPort: 端口句柄, 调用OpenCommPort函数得到,需要联机
   设备的工作模式,以位方式操作(低八位)以上是帮助文本里的说明,C#中我是这样的:[DllImport("EastRiver.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
 public static extern bool SetClockModeEx(IntPtr handle, int Mode, int ExtraMode, int SystemMode, int RingMode);我要传的后4个值是103  7 0 0 对应的8位二进制分别是  01100111   00000111  00000000  00000000
数据类型,int double string stringBulider我都试过了,结果就是返回false
麻烦各位高手帮我看看,C#这里引用,我该怎么传值呢
我调用function GetClockModeEx(hPort: THandle; Mode: Integer; ExtraMode: Integer; 
     SystemMode: Integer; RingMode: Integer): Boolean;读取参数信息时,返回的是int类型,但是就是设置时传值有问题,有劳各位了

解决方案 »

  1.   

    GetClockModeEx的返回值不是Boolean吗?你怎么会返回int类型。
      

  2.   

    返回值有问题,改成:[DllImport("EastRiver.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    [return : MarshalAs( UnmanagedType.I1)]
    public static extern bool SetClockModeEx(IntPtr handle, int Mode, int ExtraMode, int SystemMode, int RingMode);
    I1: 1 字节有符号整数。可使用此成员将布尔值转换为 1 字节、C 样式的 bool(true = 1、false = 0)。  
      

  3.   

    重载了下方法,传参时,前面加上ref就OK了
      

  4.   

    跟你参数有什么关系,函数原型并没有使用指针或引用,不要这样使用!主要是返回值对应错误:因为不同开发平台bool处理方式不相同,需要net转换处理!C++的bool,BOOL都有这个问题,你自己可以试试...
      

  5.   

    delphi的CallingConvention是StdCall吗,试一试Cdecl或者FastCall。
      

  6.   

    google了下,好像Pascal调用约定就是StdCall。
      

  7.   

    按照那个修改试了下,还是返回false
      

  8.   

    你在Delphi中怎么使用这个函数的,贴出那几行代码?
      

  9.   

    我是调用别人的dll的,delphi中的代码我是看不到到,只能在帮助文档中看到这个:
    //      扩展读取机具工作模式
    function ReadClockModeEx(hPort: THandle; var Mode: Integer; var ExtraMode: Integer; var SystemMode: Integer; var RingMode: Integer): Boolean; stdcall; external EASTRIVER_API
     扩展设置设备工作模式
    function SetClockModeEx(hPort: THandle; Mode: Integer; ExtraMode: Integer; SystemMode: Integer; RingMode: Integer): Boolean; stdcall; external EASTRIVER_API
      

  10.   

    你没有这个Dll的Delphi的Demo测试程序?如果确实没有,那你可以用VC测试一下,看看问题处在哪里?
      

  11.   

    Demo里没有用到这个方法,但是测试程序能够实现这个方法的功能