用Delphi写DLL,用户要求的函数格式是C的格式,在Delphi中如何定义?
用户要求我们提供DLL,DLL中需要提供以下函数
写好的DLL必须能在VC,和Delphi中使用
我主要是不知道下列函数的参数在Delphi中是如何定义的
也就是C的数据类型和Delphi的数据类型的对应关系.
望高手大哥给小弟指点以下
1)int _stdcall SetCom(char *comNo,int bps)
说明:设置串口:
参数:char *comNo:串口号(如com1,com2,com5等),默认为com1;
      int bps:传输速率,默认为9600bps;
返回:0 设置成功;-1 设置失败。2)int _stdcall Test(char *bStatus)
返回:0 成功 -1 失败。
     char *bStatus设备状态;
     设备状态采用1个字节(8位)按位表示各部件状态,其中0-正常,1-故障;3)int _stdcall DevData(int ID,long *Weight,long *WtLimit,int AxisType[10],double *speed)

解决方案 »

  1.   

    1) function SetCom(comNo:pchar;bps:integer):integer;stdcall;
    2) function Test(bStatus:pchar):integer;stdcall;
    3) function DevData(ID:integer;Weight,WtLimit:plongint;AxisType:array[0..9] of integer;speed:pDouble):integer;stdcall;
      

  2.   

    Delphi的定义:
    1)function SetCom(comNo: PChar; bps: integer): integer;stdcall;2)function Test(bStatus: PChar): integer;stdcall;3)function DevData(ID: Integer; var Weight: DWORD; var WtLimit: DWORD; AxisType: array of integer; var speed: double): integer;stdcall;从这些函数的定义中看出楼主好像是汽车检测行业方面的。
      

  3.   

    function SetCom(comNo: PChar; bps: integer): integer;stdcall;
    改为
    function SetCom(comNo: string; bps: integer): integer;stdcall;
    可以吗
      

  4.   

    1)int _stdcall SetCom(char *comNo,int bps)
    function SetCom(comNo:PChar;bps:Intger):Integer;stdcall;
    或者
    function SetCom(const comNo:string;bps:Intger):Integer;stdcall;
    2)int _stdcall Test(char *bStatus)
     function Test(bStatus:PChar):Integer;stdcall;
     function Test(const bStatus:String):Integer;stdcall;3)int _stdcall DevData(int ID,long *Weight,long *WtLimit,int AxisType[10],double *speed)
    function DevData(ID:Integer;var Weight:Cardinal;var WtLimit:Cardinal;AxisType:array[0..9] of Integer,var speed:double):Integer;stdcall;只要你的字符串是传入的,可以使用const+string代替PChar
      

  5.   

    貌似调用方式用cdecl更好点,既然他们说要c格式的话;
    stdcall的话跟他们吼一声免得到时候大家一起郁闷。
      

  6.   

    是应该说明调用方式,但他给的例子是stdcall,应该不会错。