vc 实现的DLL,接口中有一个结构体,结构体为
typedef struct{  
 unsigned int  filter;
 unsigned int  lis_on;
 unsigned int  test;
 unsigned int  sleep;
 unsigned int  baud_rate;
 unsigned char code1;
}PORT_STRUCT;函数调用为
int __stdcall CreateObjectofA1(PORT_STRUCT stu_packet);在VB中如何实现CreateObjectofA1 的参数设置
(目前如果不参进结构体的unsigned char code1;成员,VB中已经调试通过,但是加进来后就不能,提示为Bad dll calling convention)这个问题我个人认为比较有意思,请各位研究一下

解决方案 »

  1.   

    Declare Function CreateObjectofA1 Lib "StructTst.dll" (can_partStr As Any) As Long这是我的声明
      

  2.   

    Private Type PORT_STRUCT
         filter As Integer
         lis_on As Integer
         test As Integer
         sleep As Integer
         baud_rate As Integer
         code1 As String
    End TypeDeclare Function CreateObjectofA1 Lib "StructTst.dll" (Byref can_partStr As PORT_STRUCT ) As Long
      

  3.   

    Private Type PORT_STRUCT
         filter As Long
         lis_on As Long
         test As Long
         sleep As Long
         baud_rate As Long
         code1 As String
    End TypeDeclare Function CreateObjectofA1 Lib "StructTst.dll" (Byref can_partStr As PORT_STRUCT ) As Long
      

  4.   

    以下是我的声明
    public Type CAN_PACKET
        can_part1 As Long
        can_part2 As Long
        can_part3 As Long
        can_part4 As Long
        can_part5 As Long
        can_part6 As String
    End TypeDeclare Function CreateObjectofA1 Lib "StructTst.dll" (ByRef can_partStr As CAN_PACKET) As Long调用为Private Sub Command1_Click()
    Dim cpart1 As CAN_PACKET
    Dim t1 As Integer
    cpart1.can_part1 = 0
    cpart1.can_part2 = 1
    cpart1.can_part3 = 2
    cpart1.can_part4 = 3
    cpart1.can_part5 = 4
    cpart1.can_part6 = 5
    t1 = CreateObjectofA1(cpart1)End Sub现在提示为byref argument type mismatch
      

  5.   

    现在不存在提示yref argument type mismatch
    提示还是:Bad dll calling convention
      

  6.   

    请教各位大哥
    小弟使用file system objects 读取文件,要从一个文本文件中读取数据,程序如下:
    Private Sub Command1_Click()
        Dim fso As New filesystemobject, txtfile, fil As File, ts As textstream
        Set txtfile = fso.createtextfile("c:\testfile.txt", True)
        MsgBox "正在写入文件"
        Set fil = fso.getfile("c:\testfile.txt")
        Set ts = fil.openastextstream(forwriting)
        ts.write "hello world"
        ts.Close
        Set ts = fil.openastextstream(forreading)
        s = ts.readline
        MsgBox s
        ts.Close
    End Sub
    程序运行后出现如下提示:

    编译错误:
    用户定义类型未定义请问是什么原因?
      

  7.   

    Type PORT_STRUCT
        filter As Long
        lis_on As Long
        test As Long
        sleep As Long
        baud_rate As Long
        code1 As Byte
    End Type
    Declare Function CreateObjectofA1 Lib "StructTst.dll" (ByVal can_partStr As PORT_STRUCT) As Long
     
      

  8.   

    VBDN(PowerBASIC 中国 http://powerbasic.cn) :老兄,你太让我感动了!晚上3、4点钟还在为我想问题,我佩服你,感谢你!
      

  9.   

    现在问题的进展很大,提出的问题已经快解决了,目前的状态:
    vc 实现的DLL,接口中有一个结构体,结构体为
    typedef struct{ 
     unsigned int  filter;
     unsigned int  lis_on;
     unsigned int  test;
     unsigned int  sleep;
     unsigned int  baud_rate;
     unsigned char code1;
    }PORT_STRUCT;函数调用为
    int __stdcall CreateObjectofA1(PORT_STRUCT stu_packet);在VB中定义为
    Private Declare Function CreateObjectofA1 Lib "xxx.dll" (ByVal filter As Long, ByVal lis_on As Long, ByVal test As Long, ByVal sleep As Long, ByVal baud_rate As Long, ByVal code1 As Byte) As Long调用为
    r = CreateObjectofA1(1, 2, 3, 4, 5, 6)
    目前已经通过但是,当VC结构体改为
    typedef struct{ 
     unsigned int  filter;
     unsigned int  lis_on;
     unsigned int  test;
     unsigned int  sleep;
     unsigned int  baud_rate;
     unsigned char code1;
     unsigned char code2;
    }PORT_STRUCT;
    也就是结构体中多了一个unsigned char code2
    目前调试报的错误信息为:Bad dll calling convention大家来一起再跟进!!!看来成功就在眼前了,让我们一起努力(说明一下,就这个问题我在本论坛开了2个贴子,一个100分,一个50分,目前本贴的进度不如另一贴,我会随时平衡2贴的进度。不管是讨论者,还是学习者,希望我的150分能够为大家服务)
      

  10.   

    目前问题已经解决,整理如下:
    vc 实现的DLL,接口中有一个结构体,结构体为
    typedef struct{ 
     unsigned int  filter;
     unsigned int  lis_on;
     unsigned int  test;
     unsigned int  sleep;
     unsigned int  baud_rate;
     unsigned char code1;
     unsigned char code2;
    }PORT_STRUCT;函数调用为
    int __stdcall CreateObjectofA1(PORT_STRUCT stu_packet);在VB中定义为
    Private Declare Function CreateObjectofA1 Lib "xxx.dll" (ByVal filter As Long, ByVal lis_on As Long, ByVal test As Long, ByVal sleep As Long, ByVal baud_rate As Long, ByVal code12 As long) As Long调用为
    r = CreateObjectofA1(1, 2, 3, 4, 5, 7*&H100+6)如果在学习研究的过程中有疑问,请E_mail:[email protected]
    希望我能够帮助你
    再次对关心支持我的同仁们表示感谢