Private Declare Function senddata Lib "standcom.dll" _
    (ByVal comlen As Long, ByRef com As Byte, ByVal leng As Long, ByRef data As Byte, ByRef device As Byte) As Long
Private Declare Function getdata Lib "standcom.dll" _
    (ByVal comlen As Long, ByRef com As Byte, ByVal leng As Long, ByRef data As Byte, ByRef device As Byte) As Long就是这个代码

解决方案 »

  1.   

    ////////////
     function senddata(const comlen:LongInt;var com:Byte;leng:LongInt;data:Byte;device:Byte):LongInt;stdcall;External'standcom.dll';
     function getdata(comlen:LongInt;com:Byte;leng :LongInt; data : Byte; device: Byte):LongInt;stdcall;External'standcom.dll'; //////////
    我这样写,没有看到错误,但是
    procedure TForm1.Timer1Timer(Sender: TObject);
     var
      sendatalen:LongInt;
      gdata:array [0..20] of Byte;
      sdata:array [0..20] of Byte;
      gdata1:array [0..10] of Byte;
      device:array [0..11] of Byte;
      Command:array [0..10] of Byte;
      tempno:LongInt;
      tkh,tempcom,tempname,templeibi,tempstno:string;
      txfje:Double;
      intmoney:LongInt;
      longg,commandLen,ret,temp,temp1:integer;
      kh2,kh1,kh3,kh4,kh5,kh6,senddatalen:LongInt;
      rem3:double;
    begin
        tempno:= strtoint(Trim(Edit1.Text));
        tempcom:= Trim(Edit2.Text);
       // tkh = Trim(Text5.Text)
        commandLen:= 4;
        longg := 9;
        Command[0]:= tempno;
        Command[1]:= 167;
        Command[2]:= 9;
        Command[3]:= 0;
        Command[4]:= 0;
        device[0]:= ord('C');
        device[1]:= ord('O');
        device[2]:= ord('M');
        device[3]:= ord('1');
      //  online:=getdata(commandLen,pchar(Command),gdataLen, pchar(gdata),pchar(device))       ;    ret:= getdata(commandLen, Command[0], longg, gdata[0], device[0]);
        If ret <> 0 Then //在不在网上
             Label1.Caption:= '不在网上'
        Else
          begin
            temp:= gdata[0];
            temp1:= gdata[1];
            If temp1 = 167 Then //在网上
               Label1.Caption:= '在网上';        If temp1 = 168 Then  //断定卡号,及卡上的余额
              begin
               kh1:= gdata[2];   //消费模式3
               kh2:=gdata[3];
               kh3:=gdata[4];
               kh4:=gdata[5];
               kh5:=gdata[6];
               kh6:=gdata[7];
               commandLen:=4;
               senddatalen:=7;
               Command[0]:= tempno;
               Command[1]:= 168;
               Command[2]:= 7;
               Command[3]:= 0;
               Command[4]:= 0;
               sdata[0]:= kh1;
               sdata[1]:= kh2;
               sdata[2]:= kh3;
               sdata[3]:= kh4;
               rem3:= kh2 * 256 + kh3 + kh1 * 65536;
               edit3.Text:= floattostr(rem3);
            end;
          end;end;
    这样调用就出错误了
    project project1.exe raised exception class eaccessviolation 
    with message "access violation at address 1000102A in moudle'
    "standcom.dll.read of address 00000002'
    process stopped use step or run to continue
      

  2.   

    基本对,那个错误应该和这些代码没有关系,byval在d中用const或不用前缀都可以,byref在d中要用var定义,改过来就行了,另外vb的long在d中就是integer
      

  3.   

    你需要的是什么功能啊?在Delphi中直接写出来不好吗?
      

  4.   

    谢谢各位了 ,晚上我把解决的办法贴出来 在揭贴。
    to Arvin2003(梅园先生)  
    这个是人家的设备,做二次开发,人家提供的部分代码
      

  5.   

    function   getdata(comlen:longint;com:PChar;leng:longint;data,device:PChar):longint;stdcall;external'standCOM.DLL';
       function   senddata(comlen:longint;com:PChar;leng:longint;data,device:PChar):longint;stdcall;external'standCOM.DLL';
       ////////////procedure TForm1.Timer2Timer(Sender: TObject);
     var
      sendatalen:LongInt;
      gdata:array [0..20] of Byte;
      sdata:array [0..20] of Byte;
      gdata1:array [0..10] of Byte;
      device:array [0..11] of Byte;
      Command:array [0..10] of Byte;
      tempno:LongInt;
      tkh,tempcom,tempname,templeibi,tempstno:string;
      txfje:Double;
      intmoney:LongInt;
      longg,commandLen,ret,temp,temp1:integer;
      kh2,kh1,kh3,kh4,kh5,kh6,senddatalen:LongInt;
      rem3:double;
    begin
        tempno:= strtoint(Trim(Edit1.Text));
        tempcom:= Trim(Edit2.Text);
       // tkh = Trim(Text5.Text)
        commandLen:= 4;
        longg := 9;
        Command[0]:= tempno;
        Command[1]:= 167;
        Command[2]:= 9;
        Command[3]:= 0;
        Command[4]:= 0;
        device[0]:= ord('C');
        device[1]:= ord('O');
        device[2]:= ord('M');
        device[3]:= ord('1');
      //  online:=getdata(commandLen,pchar(Command),gdataLen, pchar(gdata),pchar(device))       ;
        ret:=getdata(commandLen,@Command[0],longg,@gdata[0],@device[0]);
       // ret:= getdata(commandLen, Command[0], longg, gdata[0], device[0]);
        Label2.Caption:=inttostr(ret);
        If ret <> 0 Then //在不在网上
             Label1.Caption:= '不在网上'
        Else
          begin
           // temp:= gdata[0];
            temp1:= gdata[1];
            Label3.Caption:=inttostr(temp1);
            If temp1 = 167 Then //在网上
               Label1.Caption:= '在网上';        If temp1 = 168 Then  //断定卡号,及卡上的余额
              begin
               kh1:= gdata[2];   //消费模式3
               kh2:=gdata[3];
               kh3:=gdata[4];
               rem3:= kh2 * 256 + kh3 + kh1 * 65536;
               edit3.Text:= floattostr(rem3);
            end;
          end;end;