两个动态库的原形如下,
int _stdcall IFD_InitComm(char *portname, unsigned long baud)int _stdcall IFD_SLE4442_Read(unsigned int Address, unsigned char Len, unsigned char *rData)以上两个函数,我在VB中是这样申明的:
Public Declare Function IFD_InitComm Lib "IFD_API.dll" (ByVal Pportname, baud As Long)Public Declare Function IFD_SLE4442_Read Lib "IFD_API.dll" (Address As Long, Lend As Long, ByRef PrData As Long) As Long]在VB中,调用时总是出现错误,如果调用成功反回值是0
有谁知怎么调用??我给分

解决方案 »

  1.   

    两个动态库的原形如下, 
    int _stdcall IFD_InitComm(char *portname, unsigned long baud) int _stdcall IFD_SLE4442_Read(unsigned int Address, unsigned char Len, unsigned char *rData) 
    是函数原形吧?
    还有就是你这种申明方式的函数,dll一般都应该放在STSTEM32目录下,
    不过,我建议最好是采用引用,就不用怎么麻烦了
      

  2.   

    Public Declare Function IFD_InitComm Lib "IFD_API.dll" (ByVal Pportname, baud As Long)
    以指针形式传递字符串,在VB中应该用ByRef。 Public Declare Function IFD_SLE4442_Read Lib "IFD_API.dll" (Address As Long, Lend As Long, ByRef PrData As Long) As Long] 
    prdata可以用ByVal来传递。另外在函数字义时没有返回值类型,应加上。
      

  3.   

    int _stdcall IFD_InitComm(char *portname, unsigned long baud) int _stdcall IFD_SLE4442_Read(unsigned int Address, unsigned char Len, unsigned char *rData) Public Declare Function IFD_InitComm Lib "IFD_API.dll" (ByVal Portname As String, Byval baud As Long) As LongPublic Declare Function IFD_SLE4442_Read Lib "IFD_API.dll" (Byval Address As Long, Byval Lend As Long, Byref PrData As Byte) As Long第二个函数调用方法:
    Dim ret As Long, addr As Long, length As Long
    Dim data(255) As Byteaddr = 0
    length = 16
    ret = IFD_SLE4442_Read(addr, length, data(0)) 
      

  4.   

    Public Declare Function IFD_InitComm Lib "IFD_API.dll" (ByVal Portname As String, Byval baud As Long) As Long 
    Public Declare Function IFD_SLE4442_Read Lib "IFD_API.dll" (Byval Address As Long, Byval Lend As Byte, rData As Any) As Long Dim ret As Long, addr As Long, length As byte
    Dim data(255) As Byte addr = 11223344
    length = 16 
    ret = IFD_SLE4442_Read(addr, length, data(0)) 
      

  5.   

    指针在VB里可以long型声明,如果不加byval,传指针参数的时候就要加,call fun(Byval lp),数组直接可以传第一个元素