C写的DLL中有一函数:
long senddata (long n1,char  * comand ,long n2, char  *senddata, char  *device)
在delphi中应该如何调用?
请教同志们。

解决方案 »

  1.   

    申明成:
    function senddata(n1: Longint;  comand: PChar;  n2: Longint;  senddata, device: PChar): Longint;  external 'XXX.dll';  stdcall;  //注:stdcall有可能要换成cdecl, 这取决于C中的函数头是如何定义的了
      

  2.   

    function getdata(comlen:Longint; com:PChar;  leng:Longint;  data:PChar; device:PChar): Longint;external 'STANDCOM.DLL';var
      Command:Pchar;
      gdata:Pchar;
      device:Pchar;
      longg,ret,commandLen:longint;
    begin
      commandLen:= 4;
      longg:=9;
      Command:=PChar(Trim(rzedit1.Text)+'167'+'9'+'0'+'0');
      device:=PChar('COM1');
      ret:=getdata(commandLen,Command,longg,gdata,device);
      showmessage(inttostr(ret));
    end;这样调用行吗?
      

  3.   

    var
      Command: String;
      gdata  : String;
      device : String;
      longg,ret,commandLen:longint;
    begin
      commandLen := 4;
      longg := 9;
      Command := Trim(rzedit1.Text)+'167'+'9'+'0'+'0';
      device := 'COM1';
      SetLength (gdata, 1024);    //这个gdata应该需要先分配空间的
      ret := getdata(commandLen, PChar(Command), longg, PChar(gdata), PChar(device));
      showmessage(inttostr(ret));
    end;
      

  4.   

    注意 stdcall 标志,如果对方按照API协议书写C函数,那么就必须使用 stdcall 标志,如果是按照C习惯书写的函数,就要做cdecl标志。建议双方按照API规范书写。
      

  5.   

    function senddata(comlen:Longint; com:PChar; leng:Longint;  data:PChar; device:PChar): Longint;stdcall;external 'STANDCOM.DLL';经测试没有错。