VB中:
Public Declare Function auto_init Lib "comdll.dll" (ByVal CommPort As Long, ByVal Baud As Long) As Long   '打开串口
Public Declare Function ic_exit Lib "comdll.dll" (ByRef commhandle As Long) As Long          '关闭串口
Public Declare Function lsct5557hex Lib "comdll.dll" (ByVal commhandle As Long, ByRef keystr As Byte) As Long请求DELPHI中调用写法?打开出宽方法我使用:
Function auto_init( CommPort : LongWord; Baud : LongWord):LongWord; STDCALL external dllname; //   '打开串口可是调用时出现内存错误,请 帮忙。

解决方案 »

  1.   

    procedure   TfrmMain.comMainReceiveData(Sender:   TObject;   Buffer:   Pointer;   
          BufferLength:   Word);   
      var   
          nIndex   :   Integer;   
          boolZero   :   Boolean;   
          arrByte   :   array   [1..8]   of   Byte;   
          strReceiveData   :   string;   
      begin   
          //内存移位   
          Move(Buffer^,arrByte,BufferLength);   
          strReceiveData   :=   '';   
          boolZero   :=   True;   
        
          //从高位到低位转换Buffer   
          for   nIndex   :=   BufferLength   downto   1   do   
          begin   
              if   (boolZero)   and   (Chr(arrByte[nIndex])   <>   '0')   then   
                  boolZero   :=   False;   
              if   (boolZero   =   False)   and   (Chr(arrByte[nIndex])   <>   '=')   then   
                  strReceiveData   :=   strReceiveData   +   Chr(arrByte[nIndex]);   
          end;   
        
          //屏幕显示不断刷新   
          LCDCurrentWeight.Indicatorstring   :=   strReceiveData;   
          RefreshLCD(LCDTare.Indicatorstring);   
        
          //毛重是否变化   
          if   FboolIsEnter   =   False   then   FstrGrossWeight   :=   strReceiveData;   
      end;
      

  2.   

    http://topic.csdn.net/t/20040131/14/2690640.html
      

  3.   

    没看出楼主的写法有什么问题,至多把LongWord改成Longint。
    Function auto_init(CommPort, Baud: Longint): Longint;  stdcall;  external dllname; //   '打开串口有没有测试过在VB中按VB的写法调用是否正确呢?
      

  4.   

    VB中的写法是正确的,我们编译了VB代码可以执行
      

  5.   

    串口?直接用SPCOMM得了~
    何必用DLL呢~~
      

  6.   

    Function auto_init( CommPort : Longint; Baud : Longint):Longint; stdcall;external 'dllname.DLL' NAME 'auto_init' ;
      

  7.   

    这应该是什么串口设备的接口函数.
    Function auto_init(CommPort, Baud: Integer): Integer; stdcall;external '*.dll';
    //*.dll为你的DLL文件名
      

  8.   

    Function auto_init(CommPort, Baud: Integer): Integer; stdcall;external '*.dll'  name 'auto_init';
      

  9.   

    ly_liuyang(Liu Yang LYSoft http://lysoft.7u7.net) ( ) 信誉:244    Blog  2007-3-11 13:46:41  得分: 0  
     
     
       
    串口?直接用SPCOMM得了~
    何必用DLL呢~~  
     
    他的串口操作肯定被封装在comdll.dll中了,并不是他直接对串口进行操作。
      

  10.   

    对的,还是未测试成功啊,郁闷。奇怪的是竟然VB运行一点问题都没有。Delphi我只拿最简单的初始化端口函数调用都出错
    奇怪奇怪啊 ~~~~~~~~~~直接操作SPCOMM是不可能的了,他的dll封装的东西可多呢。不是直接对串口操作的东西
      

  11.   

    注意ByVal和ByRef区别一般就没有问题了。
    ByVal按值,ByRef按地址